| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- '''
- Module github.py contains a handful of methods
- for interacting with Github data.
- '''
- import requests
- import simplejson as json
- ########################
- # GITHUB API CONSTANTS #
- ########################
- API_BASE_URL = 'https://api.github.com/'
- API_USERS_URL = API_BASE_URL + 'users/DrkSephy' + '?client_id=2404a1e21aebd902f6db' + '&client_secret=3da44769d4b7c9465fa4c812669148a163607c23'
- # Endpoint to get statistics in a repository
- # https://api.github.com/repos/DrkSephy/WaterEmblem/stats/contributors
- # https://api.github.com/repos/:user/:repo/stats/contributors
- # 'https://api.github.com/repos/DrkSephy/' + repo + '/stats/contributors' + '?client_id=2404a1e21aebd902f6db' + '&client_secret=3da44769d4b7c9465fa4c812669148a163607c23'
- def getUserData():
- req = requests.get(API_USERS_URL)
- jsonList = []
- jsonList.append(json.loads(req.content))
- parsedData = []
- userData = {}
- for data in jsonList:
- userData['name'] = data['name']
- userData['blog'] = data['blog']
- userData['email'] = data['email']
- userData['public_gists'] = data['public_gists']
- userData['public_repos'] = data['public_repos']
- userData['avatar_url'] = data['avatar_url']
- userData['followers'] = data['followers']
- userData['following'] = data['following']
- parsedData.append(userData)
- return parsedData
-
- def getUserRepositories():
- # Which page number of data are we looking at?
- pageNumber = 1
- # List of all our json
- jsonList = []
- # List of all repositories
- repositories = []
- # IDEA: Repeatedly loop over urls and check if the content has less than 30 entries.
- # If it does, then we have iterated over all the data. Time to parse it.
- while True:
- req = requests.get('https://api.github.com/users/DrkSephy/repos?page=' + str(pageNumber) + '&client_id=2404a1e21aebd902f6db&client_secret=3da44769d4b7c9465fa4c812669148a163607c23')
- jsonList.append(json.loads(req.content))
- if len(json.loads(req.content)) < 30:
- break
- elif len(json.loads(req.content)) >= 30:
- pageNumber += 1
- # Loop over our data and extract all of the repository names
- for data in jsonList:
- for datum in data:
- repositories.append(datum['name'])
- return repositories
- def getTopContributedRepositories(repos):
- jsonList = []
- for repo in repos:
- # print repo
- req = requests.get('https://api.github.com/repos/DrkSephy/' + repo + '/stats/contributors' + '?client_id=2404a1e21aebd902f6db' + '&client_secret=3da44769d4b7c9465fa4c812669148a163607c23')
- jsonList.append(json.loads(req.content))
- parsedData = []
- for item in jsonList:
- commits = {}
- for data in item:
- if data['author']['login'] == 'DrkSephy':
- commits['author'] = data['author']['login']
- commits['total'] = data['total']
- parsedData.append(commits)
- print parsedData
-
- '''
- data = {}
- if datum['author']['login'] == 'DrkSephy':
- data['author'] = datum['author']['login']
- data['total'] = datum['total']
- parsedData.append(data)
- '''
- #print len(jsonList)
- #print parsedData
-
-
|