'How to find the last page of github api using urllib
I am using a script for getting the metrics of github repositories using github API.
The line which sends the request is like this:
import urllib.request
request_url = urllib.request.urlopen('https://api.github.com/repos/freeCodeCamp/freeCodeCamp/commits?page=1&per_page=100')
I want to find the last page that contains information, so only get the data of that page (for example, page=20). How should I do it?
Solution 1:[1]
I would suggest to use GitHub's GraphQL API. This will return what you want. Try it out in the explorer here
{
repository(owner: "freeCodeCamp", name: "freeCodeCamp") {
defaultBranchRef {
target {
... on Commit {
history {
totalCount
edges {
node {
oid
pushedDate
}
}
pageInfo {
hasNextPage
}
}
}
}
}
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | David Butler |
