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

Add `last` keyword to API #1254

Closed
hunterowens opened this issue Sep 26, 2018 · 2 comments
Closed

Add `last` keyword to API #1254

hunterowens opened this issue Sep 26, 2018 · 2 comments
Assignees
Labels

Comments

@hunterowens
Copy link

@hunterowens hunterowens commented Sep 26, 2018

~ Hi Transitland Team ~

Awesome API. I'm currently using to answer a very silly question I had on twitter.. to do this, I'm loading all the bus stops in the California bounding box, by using urls such as https://api.transit.land/api/v1/stops?bbox=-124.48%2C32.53%2C-114.13%2C42.01&offset=31350&per_page=50&sort_key=id&sort_order=asc.

My code is as follows:

while r.json()['meta']['next']: 
    nxt = r.json()['meta']['next']
    print("getting {}", nxt)
    r = requests.get(nxt)
    stops.append(r.json()['stops'])

Since there is no last keyword, it is hard to do these requests asynchronously and speed up the loading process.

Two questions:

  1. Is there a better way to bulk load stop data?
  2. If not, would it be possible to add a last keyword so that somebody could generate a list of URLs and then using multithreading/etc to speed up loading?
@drewda drewda added the question label Sep 26, 2018
@drewda

This comment has been minimized.

Copy link
Member

@drewda drewda commented Sep 26, 2018

@hunterowens thanks for your (interesting) application and question!

Computing the total count of possible records can be expensive on some complex queries, that's why we don't compute the last page. If you want to do this yourself, you can start with a single request to /api/v1/stops?per_page=0&total=true (along with your other query params). This will give you a total that you can use to calculate the number of pages to request.

Also, if you find your queries are slowing down with high offset values, you can switch to using the min_id query parameter instead. (That takes more advantage of the underlying database's indexes.)

Finally, we do have static extracts of stops and other data in the works for the future -- but it's not yet available for external use.

Hope this helps -- feel free to reopen with any further questions or suggestions.

@drewda drewda closed this Sep 26, 2018
@drewda drewda self-assigned this Sep 26, 2018
@kylebarron

This comment has been minimized.

Copy link

@kylebarron kylebarron commented Feb 21, 2020

Finally, we do have static extracts of stops and other data in the works for the future -- but it's not yet available for external use.

Did anything come out of that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.