Created
February 17, 2015 16:17
-
-
Save nevalsar/f38ff9e4ed70699ffc56 to your computer and use it in GitHub Desktop.
Get contribution count of user on GitHub
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# Python script to get the day's contribution count from user's GitHub account | |
# Use flag -h for parameter information | |
import urllib2 | |
from bs4 import BeautifulSoup | |
import argparse | |
# parse args and set parameter details | |
parser = argparse.ArgumentParser(description='Get GitHub contribution data') | |
parser.add_argument('-u', '--username', metavar='<username>', | |
type=str, default='routeaccess', help='GiHub username') | |
parser.add_argument('-d', '--days', metavar='<days>', | |
type=int, default=0, help='No of days previously') | |
args = parser.parse_args() | |
# fetch user profile | |
try: | |
response = urllib2.urlopen('https://github.com/' + args.username) | |
except urllib2.URLError, e: | |
print('URLError = ' + str(e.reason) + "\n") | |
except Exception: | |
import traceback | |
print('Generic exception: ' + traceback.format_exc()) | |
# parse page for details | |
soup = BeautifulSoup(response.read()) | |
count = soup.find( | |
'svg', | |
'js-calendar-graph-svg' | |
).find_all('rect')[-1 - args.days]['data-count'] | |
# print output to stdout | |
print("\nUser \t\t: " + args.username + | |
"\nContribution \t: " + count + " commit(s)") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment