| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- '''
- 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'
- 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 = []
- # Keep track of which JSON set we are processing to get the repo name
- indexNumber = -1
- for item in jsonList:
- indexNumber += 1
- commits = {}
- for data in item:
- if data['author']['login'] == 'DrkSephy':
- commits['author'] = data['author']['login']
- commits['total'] = data['total']
- commits['repo_name'] = repos[indexNumber]
- parsedData.append(commits)
- return parsedData
- def filterCommits(data):
- maxCommits = []
- for i in range(1, 10):
- maxCommitedRepo = max(data, key=lambda x:x['total'])
- maxCommits.append(maxCommitedRepo)
- index = data.index(maxCommitedRepo)
- data.pop(index)
- return maxCommits
-
-
- def getStarGazerCount():
- # Which page number of data are we looking at?
- pageNumber = 1
- # List of all our json
- jsonList = []
- # List of all repositories
- stargazers = []
- # 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:
- starData = {}
- starData['stargazers_count'] = datum['stargazers_count']
- starData['name'] = datum['name']
- stargazers.append(starData)
- return stargazers
- def filterStarGazerCount(data):
- maxStars= []
- for i in range(1, 10):
- maxStarGazers = max(data, key=lambda x:x['stargazers_count'])
- maxCommits.append(maxStarGazers)
- index = data.index(maxStarGazers)
- data.pop(index)
- return maxStars
|