githubpy icon indicating copy to clipboard operation
githubpy copied to clipboard

Doesn't handle pagination all that elegantly

Open vrillusions opened this issue 11 years ago • 1 comments

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.

vrillusions avatar Mar 20 '14 04:03 vrillusions

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

ghost avatar Mar 28 '16 14:03 ghost