Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pull search information with POST and json data #9

Closed
nalvarez508 opened this issue Apr 1, 2022 · 6 comments
Closed

Pull search information with POST and json data #9

nalvarez508 opened this issue Apr 1, 2022 · 6 comments
Assignees
Labels
backend Mainly a backend change enhancement New feature or request

Comments

@nalvarez508
Copy link
Owner

Included in a (future) commit are a headers file and resulting search results json data (stored in session storage). At the very least, the data could be parsed quicker than checking each browser element could.

@nalvarez508 nalvarez508 added the enhancement New feature or request label Apr 1, 2022
@nalvarez508 nalvarez508 self-assigned this Apr 1, 2022
@nalvarez508 nalvarez508 added the backend Mainly a backend change label Apr 1, 2022
@nalvarez508
Copy link
Owner Author

nalvarez508 commented Apr 6, 2022

Tested with curl -i -X POST -H 'Content-Type: application/json' -d <somedata> https://www.amtrak.com/v4/journey-solution-option may have to try with cookies or through a browser.
One thought is to get cookies from a chromedriver session and pass this in the post request
This returned the default "couldn't process your request" error from amtrak's site, same as when using an unmodified webdriver

@nalvarez508
Copy link
Owner Author

nalvarez508 commented Apr 6, 2022

Parsing session storage worked. Each train is stored in the following path:

journeySolutionOption : dict
  journeyLegs : list (of one dict)
    journeyLegOptions : list (of all results as dict)
      % data stored in here as a mix of list of lists and dicts

This not only makes parsing a page faster as we just need session storage, but it also reveals a lot of hidden data such as fare types and train information for multiple segments, seating accommodations, etc. Would need a deep dive.

@nalvarez508
Copy link
Owner Author

Useful keys from session storage.
searchresults is the meat of what we're after
stationsData_stations returns a list of every location served by amtrak, train or bus
traincodes returns every train by number. Train website is /firstword-secondword-train.
The latter two can be retrieved just by going to amtrak.com

@nalvarez508
Copy link
Owner Author

After closer examination:

  • traincodes is useful, but for what, I am not sure in this application
  • stationsData_stations is great and well formatted but includes bus stops which seems out of scope at this point. However I would not be opposed to including this feature later, perhaps as an "Include Bus Stops" option.
  • searchresults I really want to work but it still requires that we use a search, and with a webdriver, what's the point

@nalvarez508
Copy link
Owner Author

JSON data only

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend Mainly a backend change enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant