Playing with Github Api - GitLinks


In [2]:
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
%matplotlib inline

In [3]:
from github import Github #http://jacquev6.net/PyGithub/v1/introduction.html

In [4]:
import os
user = os.environ['GITHUB_USER']
token = os.environ['GITHUB_TOKEN']
password = os.environ['GITHUB_PASSWORD']

In [5]:
g = Github(token)

In [6]:
print g.rate_limiting
from datetime import datetime
print datetime.fromtimestamp(g.rate_limiting_resettime)


(4958, 5000)
2015-05-27 22:06:49

Search users or get user

We use :

  • GET /search/users
  • GET /users/:username
  • GET /user/repos

In [7]:
users = ["pocman", "callicles", "jacobtardieu", "sheymann"]
searched_users = [g.search_users(u) for u in users]
get_users = [g.get_user(u) for u in users]

In [8]:
for u in get_users:
    print "_________%s_________" % u.name
    for r in u.get_repos():
        print r.full_name


_________Thomas_________
pocman/AircraftLanding
pocman/awesome-bigdata
pocman/Census_analysis
pocman/cs109
pocman/docker-kafka
pocman/elasticsearch
pocman/gitATrouverUnNomIdiot
pocman/hermann
pocman/Ipipip
pocman/Probabilistic-Programming-and-Bayesian-Methods-for-Hackers
pocman/s2-geometry-library
pocman/s2-geometry-library-java-sbt
_________Nicolas Joseph_________
callicles/firestorm-prototype
callicles/firestorm-test
callicles/flot-events
callicles/is.js
callicles/meteor-invite
callicles/MinesTravelStarkTeam
callicles/OCAapplication
callicles/PortfolioWordPressTheme
callicles/scanjs
callicles/scanjs-devtools
callicles/VivaldiMonitoringDart
callicles/VivaldiMonitoringPlay
_________Jacob Tardieu_________
jacobtardieu/furry-octo-bear
jacobtardieu/MinesTravel
jacobtardieu/Netwemo
jacobtardieu/oh-my-zsh
jacobtardieu/phoenix
jacobtardieu/sandwichOrder
jacobtardieu/tinderbox
jacobtardieu/translationChooser
_________Sébastien Heymann_________
sheymann/apidoc
sheymann/batch-import
sheymann/beamer-lip6-template
sheymann/blueprints
sheymann/chroma.js
sheymann/color
sheymann/docco
sheymann/edgestream-to-neo4j
sheymann/gephi
sheymann/gexf-primer
sheymann/gitbook-test
sheymann/githubarchive.org
sheymann/grunt-template-jasmine-sigmajs
sheymann/isigma.js
sheymann/iwanthue
sheymann/jLouvain
sheymann/jquery.tristate
sheymann/mod-tinkerpop-persistor
sheymann/ng-doodle
sheymann/ngbp
sheymann/outskewer
sheymann/outskewer.r
sheymann/palettes
sheymann/sigma.js
sheymann/visuweb

In [9]:
get_repos = { u.login : u.get_repos() for u in get_users }

Search code for user weight

we use:

  • GET /search/code

In [19]:
import time
for user, repos in get_repos.items():
    print "_________%s______" % user
    for code in g.search_code("bootstrap user:%s" % user):
        print code.name


_________callicles______
install.rdf
dataTables.bootstrap.js
bootstrap.dart
bootstrap.dart
angular.dart
angular.dart
metisMenu.css
bootstrap.js
bootstrap.js
dart.js
dart.js
index.html
metisMenu.js
bootstrap.js
dropdown.dart
dropdown.dart
monitoringvivaldiclient.html
template_cache.dart
template_cache.dart
build.txt
sb-admin-2.css
bootstrap-theme.css
bootstrap-theme.css.map
filter.dart
filter.dart
bootstrap-theme.css.map
bootstrap-theme.css
bootstrap.css.map
bootstrap.css.map
variables.less
_variables.scss
bootstrap.css
bootstrap.css
bootstrap.css
bootstrap.css
_________pocman______
_________sheymann______
events.less
register.less
bower.json
variables.less
build.config.js
app.less
index.html
README.md
tools.md
nodeshapes.html
project.sublime-workspace
_________jacobtardieu______
layout.html
main.scala.html
main.html
bootstrap.js
Bootstrap.java
bootstrap.js
build.txt
bootstrap-theme.css
bootstrap-theme.css.map
bootstrap.css.map
web.xml
web.xml
web.xml
bootstrap-responsive.css
bootstrap.css
bootstrap.css

User Karma

Some stats about user's repos


In [83]:
for u, repos in get_repos.items():
    print "_______%s______", u
    for r in repos:
        print "forked: %s ------ starts: %d" % (r.fork, r.stargazers_count)


_______%s______ callicles
forked: False ------ starts: 0
forked: False ------ starts: 0
forked: True ------ starts: 0
forked: True ------ starts: 0
forked: False ------ starts: 1
forked: False ------ starts: 0
forked: False ------ starts: 0
forked: True ------ starts: 0
forked: True ------ starts: 0
forked: False ------ starts: 0
forked: False ------ starts: 1
forked: False ------ starts: 1
_______%s______ pocman
forked: False ------ starts: 1
forked: True ------ starts: 0
forked: False ------ starts: 0
forked: False ------ starts: 0
forked: True ------ starts: 0
forked: True ------ starts: 0
forked: False ------ starts: 0
forked: True ------ starts: 0
forked: False ------ starts: 1
forked: True ------ starts: 0
forked: False ------ starts: 0
forked: False ------ starts: 0
_______%s______ sheymann
forked: True ------ starts: 0
forked: True ------ starts: 0
forked: False ------ starts: 5
forked: True ------ starts: 0
forked: True ------ starts: 0
forked: True ------ starts: 0
forked: True ------ starts: 0
forked: False ------ starts: 0
forked: True ------ starts: 1
forked: False ------ starts: 9
forked: False ------ starts: 0
forked: True ------ starts: 2
forked: False ------ starts: 0
forked: False ------ starts: 9
forked: True ------ starts: 0
forked: True ------ starts: 0
forked: True ------ starts: 0
forked: True ------ starts: 0
forked: False ------ starts: 0
forked: True ------ starts: 0
forked: False ------ starts: 3
forked: False ------ starts: 3
forked: True ------ starts: 0
forked: True ------ starts: 0
forked: False ------ starts: 2
_______%s______ jacobtardieu
forked: False ------ starts: 0
forked: False ------ starts: 0
forked: False ------ starts: 0
forked: True ------ starts: 0
forked: True ------ starts: 0
forked: False ------ starts: 0
forked: True ------ starts: 0
forked: False ------ starts: 2

We use the list of all contributors for every user's repo GET /repos/:owner/:repo/contributors. For each contributor, we can use GET /repos/:owner/:repo/stats/contributors that will return line contribution for that user.


In [90]:
for u, repos in get_repos.items():
    print "_______%s______" % u
    for r in repos:
        try:
            contributions = [1 for c in r.get_contributors()]
            print "forked: %s ------ contributors: %d" % (r.fork, len(contributions))
        except TypeError:
            print "forked: %s ------ contributors: 0" % r.fork


_______callicles______
forked: False ------ contributors: 1
forked: False ------ contributors: 1
forked: True ------ contributors: 2
forked: True ------ contributors: 21
forked: False ------ contributors: 1
forked: False ------ contributors: 7
forked: False ------ contributors: 2
forked: True ------ contributors: 21
forked: True ------ contributors: 8
forked: False ------ contributors: 1
forked: False ------ contributors: 1
forked: False ------ contributors: 1
_______pocman______
forked: False ------ contributors: 4
forked: True ------ contributors: 16
forked: False ------ contributors: 1
forked: False ------ contributors: 13
forked: True ------ contributors: 3
forked: True ------ contributors: 248
forked: False ------ contributors: 3
forked: True ------ contributors: 5
forked: %s ------ contributors: 0
forked: True ------ contributors: 79
forked: False ------ contributors: 0
forked: False ------ contributors: 1
_______sheymann______
forked: True ------ contributors: 9
forked: True ------ contributors: 5
forked: False ------ contributors: 1
forked: True ------ contributors: 34
forked: True ------ contributors: 4
forked: True ------ contributors: 2
forked: True ------ contributors: 47
forked: False ------ contributors: 1
forked: True ------ contributors: 14
forked: False ------ contributors: 2
forked: False ------ contributors: 1
forked: True ------ contributors: 4
forked: False ------ contributors: 1
forked: False ------ contributors: 7
forked: True ------ contributors: 3
forked: True ------ contributors: 1
forked: True ------ contributors: 1
forked: True ------ contributors: 1
forked: False ------ contributors: 1
forked: True ------ contributors: 12
forked: False ------ contributors: 1
forked: False ------ contributors: 1
forked: True ------ contributors: 1
forked: True ------ contributors: 9
forked: False ------ contributors: 1
_______jacobtardieu______
forked: False ------ contributors: 8
forked: False ------ contributors: 8
forked: False ------ contributors: 1
forked: True ------ contributors: 422
forked: True ------ contributors: 19
forked: False ------ contributors: 2
forked: True ------ contributors: 11
forked: False ------ contributors: 2

TODO : Still don't know how to find every repo the user contributed to


In [ ]: