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

Doesn't handle pagination all that elegantly #7

Open
vrillusions opened this issue Mar 20, 2014 · 1 comment
Open

Doesn't handle pagination all that elegantly #7

vrillusions opened this issue Mar 20, 2014 · 1 comment

Comments

@vrillusions
Copy link

Apologies on the hackyness of this but I just wanted to show what I guess is the current way to deal with pagination:

    gh = GitHub(username=user, access_token=api_key)
    page = 1
    repos = []
    while True:
        print('page {}'.format(page))
        result = gh.user.repos.get(page=page)
        if len(result) > 0:
            repos = repos + result
            page = page + 1
        else:
            break
    template = ' {} {}'
    print(template.format('NAME', 'SSH URL'))
    for repo in repos:
        print(template.format(repo['name'], repo['ssh_url']))

Like I said, kinda messy but would be better if there was some way to get info. It's returned in the link header per the docs and this wouldn't work with the commits api because it's based on sha hashes. It is also possible to set per_page=100 which would solve it in my case (have 50ish) but I'm sure others that are more fork happy would easily exceed that.

@ghost
Copy link

ghost commented Mar 28, 2016

Thanks for the tip. I found I had to do page=str(page) instead of page=page though.

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

1 participant