Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Conversation

@twidi
Copy link
Contributor

@twidi twidi commented Oct 17, 2011

For each method asking github for a list, i added a page parameter, default to None.

The get_values method catch this paramter and then create (or update) a post_data paramter sent to make_request.

There is no easy way with the current code to know how much pages exist for a given list, so it's up to the user to manage the number of pages to retrieve.

In my code i do something like this:

# store all data from all pages
result = []
# start with page one
page = 1
# we don't know yet the max length of a page
max_length = 0

while True:
    # get data for the current page
    page_result = github.repos.watching(username, page=page)
    # no result ? it's the end
    if not page_result:
        break
    # save the result
    result += page_result
    # check length of result
    l_page = len(page_result)
    # if smaller than max, it's the last page
    if l_page < max_length:
        break
    # if bigger, it's the new max
    if l_page > max_length:
        max_length = l_page
    # go next page
    page += 1

return result

@svetlyak40wt
Copy link

Try to use my https://github.com/svetlyak40wt/pagerator/ because it is able to replace all these crapy lines of code with just one line:

return pagerator.IterableQuery(lambda page: github.repos.watching(username, page=page), PAGE_SIZE)

But you have to know default page size, which is 30 for GitHub API v3.

@svetlyak40wt
Copy link

By the way, some time ago, I found that API v2 does not support "page" argument in few places. I don't remember which exactly, but they won't fix it and advice to use API v3, where nice pageration is available, using "Link" http header.

@twidi
Copy link
Contributor Author

twidi commented Oct 17, 2011

Ok, good to know for the page argument forbidden in some calls. We'll have to check all of them... :-/

For the pagerator, i don't know all page size in the api v2, the documentation is poor or inexact.

Thanks for your comments.

PS : btw header are present in the api v2, with x-next, x-prev and x-last, but the headers are ignored too deeply in the python-github2 code

@twidi
Copy link
Contributor Author

twidi commented Oct 17, 2011

PS : btw all my "crapy lines of code" (i kwno they are), are in one and only one place, in a method in my code called each time i want all the content.

@twidi
Copy link
Contributor Author

twidi commented Oct 17, 2011

I just removed the page parameter for a lot of lists.

Here the only ones that seem to support it :

  • repositories.py => list, watching
  • pull_requests.py => list
  • commits.py => list

All return a empty list when the given page is too big, except for the list of commit which raise a 404.

And all return max 100 items per request (documentation says 30 sometimes)

And all search query return max 100 results, without pagination.

@svetlyak40wt
Copy link

@twidi, by the way, I'm going to build something very close to yours repos.io, but with slightly different feature set. And I'll be using "requests" library and raw GitHub API v3 without any wrappers.

If you are interested in my thoughts about the project, subscribe to my blog: http://dev.svetlyak.ru

@twidi
Copy link
Contributor Author

twidi commented Oct 18, 2011

@svetlyak40wt cool, let me know ! (but for now i can't read russian)

@svetlyak40wt
Copy link

I'm trying to translate most posts in english too. Subscribe on translations only: http://dev.svetlyak.ru/feeds/all-en

Today I'll publish a report with GitHub's users and reps statistics.

@JNRowe
Copy link
Collaborator

JNRowe commented Oct 18, 2011

Haven't spent much time looking at this... but I think this should be merged.

There are a few problems that need fixing before that can happen:

  • No tests
  • No examples in docs
  • [cosmetic] The page keyword docs are broken; lines too long, missing parenthesis

If I get time later today or tomorrow, I'll take a stab at it. Feel free to beat me to it ;)

@twidi
Copy link
Contributor Author

twidi commented Oct 18, 2011

I'm sorry, i looked at the documentation but didn't know where to put this.

And tests are broken for me (some repositories doesn't exist anymore ?)

Sorry... half of the patch for me, the other for you ? :) (no, sorry, really, i needed it quickly...)

@JNRowe
Copy link
Collaborator

JNRowe commented Oct 19, 2011

Something like JNRowe/python-github2@feat/page_support.

Very small changes:

  1. Default to 1 for page argument, it makes more sense than None when looking at the signature in my opinion
  2. Rebased for a cleaner history

There should be no functional changes to your version. Hopefully, no problems will arise and this can be merged soon.

Update: I was going to collapse my commits too, but I forgot. Bah, I fix that later.

@twidi
Copy link
Contributor Author

twidi commented Oct 19, 2011

You just rock :)

Something funny i just discovered: sometimes, github returns ALL the data instead of just the first page (for list of watching repositories, at least).... "Funny"... :-/

@JNRowe
Copy link
Collaborator

JNRowe commented Oct 19, 2011

Something funny i just discovered: sometimes, github returns ALL the data instead of just the first page (for list of watching repositories, at least).... "Funny"... :-/

I need to play with it some more, but I haven't seen this yet.

I was tempted to expose the x-{next,last} headers more directly(nudged by your earlier comment), but they don't appear to be uniformly supported across the API for v2.

Ξ Projects/python-github2 git:(master) ▶ curl -I https://github.com/api/v2/json/repos/watched/tekkub | egrep '^X-(Nex|Las)t'
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0 41503    0     0    0     0      0      0 --:--:--  0:00:02 --:--:--     0
X-Next: https://github.com/api/v2/json/repos/watched/tekkub?page=2
X-Last: https://github.com/api/v2/json/repos/watched/tekkub?page=2
Ξ Projects/python-github2 git:(master) ▶ curl -I  https://github.com/api/v2/json/pulls/robbyrussell/oh-my-zsh/open | egrep '^X-(Nex|Las)t'
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0  309k    0     0    0     0      0      0 --:--:--  0:00:04 --:--:--     0
↑1 Projects/python-github2 git:(master) ▶

@JNRowe JNRowe closed this in 307d736 Oct 20, 2011
@JNRowe
Copy link
Collaborator

JNRowe commented Oct 20, 2011

@twidi Merged, thanks!

The peculiarities of the API's data not withstanding I do feel this is an improvement.

@twidi
Copy link
Contributor Author

twidi commented Oct 20, 2011

Thanks a lot @JNRowe !

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

Successfully merging this pull request may close these issues.

3 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.