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

When use api/v4, will only get the last 20 records #21

Open
EastGaint opened this issue Oct 21, 2020 · 2 comments
Open

When use api/v4, will only get the last 20 records #21

EastGaint opened this issue Oct 21, 2020 · 2 comments

Comments

@EastGaint
Copy link

After check the code, I found the header of api/v4 has not contains "X-Total-Pages", so we cannot get the total page. The "X-Next-Page" is a good solution, if the records are read to end, this attribute will empty.

params = {'page': 1}
resp = request(url, params)
for row in resp.json():
yield row
next_page_s = resp.headers.get('X-Next-Page', 1)
while len(next_page_s) != 0:
next_page_i = int(next_page_s)
params['page'] = next_page_i
resp = request(url, params)
next_page_s = resp.headers.get('X-Next-Page', 1)
for row in resp.json():
yield row

@EastGaint
Copy link
Author

def gen_request(url): next_page_s = "1" while len(next_page_s) != 0: next_page_i = int(next_page_s) params = {'page': next_page_i} resp = request(url, params) next_page_s = resp.headers.get('X-Next-Page', 1) for row in resp.json(): yield row

@faouzelfassi
Copy link

Hi @EastGaint, thanks for the issue!
Is there something new on this one?

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

No branches or pull requests

2 participants