Github API v3 - Collect contributions


In [2]:
import os
# Use PyGithub Lib
import github
from datetime import datetime

token = os.environ['CHANGELOG_GITHUB_TOKEN']
g = github.Github(token)
init_rate = g.rate_limiting

print str(init_rate)
print datetime.fromtimestamp(g.rate_limiting_resettime) 

user = g.get_user('callicles')
pushs = {}
print "%s alias %s" % (user.name, user.login)

for event in user.get_public_events():
    if event.type == 'PushEvent':
        try:
            if event.repo.full_name in pushs:
                pushs[event.repo.full_name] +=1
            else:
                pushs[event.repo.full_name] = 1
                
            #print "Event: %s, on repo: %s" % (event.type, event.repo.full_name)
        except github.GithubException:
            #print "Unkown Repo"
            pass

repo_commits = {}
user_commits = {}
for repo, pushsCount in pushs.iteritems():
    user_commits[repo] = 0
    repo_commits[repo] = 0
    for commit in g.get_repo(repo).get_commits():
        if commit.author is not None and commit.author.login == user.login:
            user_commits[repo] += 1
        repo_commits[repo] +=1
        
rate_limit = g.rate_limiting
print "============================================"
print "-> API Limit state: %s" % str(rate_limit)
print "---> Consumed %d requests" % (init_rate[0] - rate_limit[0])
print "-> Contributions collected:"
for repo, pushsCount in pushs.iteritems():
    print "%s : %d commits in %d pushs on %d total commits" % (repo, user_commits[repo], pushsCount, repo_commits[repo])


(4783, 5000)
2015-06-01 20:35:10
Nicolas Joseph alias callicles
============================================
-> API Limit state: (4571, 5000)
---> Consumed 212 requests
-> Contributions collected:
Linkurious/linkurious.js : 15 commits in 22 pushs on 1500 total commits
gitlinks/gitrank-web : 1 commits in 1 pushs on 4 total commits
callicles/flot-events : 1 commits in 2 pushs on 25 total commits
Linkurious/angular-performance : 57 commits in 61 pushs on 57 total commits
callicles/meteor-invite : 4 commits in 3 pushs on 4 total commits
gitlinks/notebooks : 3 commits in 3 pushs on 9 total commits
ChambreSonore/Web-Template : 4 commits in 3 pushs on 36 total commits
ChambreSonore/webApp : 25 commits in 23 pushs on 25 total commits
gitlinks/github-rank-project : 12 commits in 5 pushs on 16 total commits

In [ ]: