فهرست منبع

Intermediate work on parsing through all user's repositories for commit counts

David Leonard 10 سال پیش
والد
کامیت
f78263fddb
2فایلهای تغییر یافته به همراه39 افزوده شده و 17 حذف شده
  1. 37 16
      hackathon_starter/hackathon/scripts/github.py
  2. 2 1
      hackathon_starter/hackathon/views.py

+ 37 - 16
hackathon_starter/hackathon/scripts/github.py

@@ -16,6 +16,8 @@ API_USERS_URL = API_BASE_URL + 'users/DrkSephy' + '?client_id=2404a1e21aebd902f6
 # Endpoint to get statistics in a repository
 # Endpoint to get statistics in a repository
 # https://api.github.com/repos/DrkSephy/WaterEmblem/stats/contributors
 # https://api.github.com/repos/DrkSephy/WaterEmblem/stats/contributors
 # https://api.github.com/repos/:user/:repo/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():
 def getUserData():
 	req = requests.get(API_USERS_URL)
 	req = requests.get(API_USERS_URL)
@@ -57,24 +59,43 @@ def getUserRepositories():
 		elif len(json.loads(req.content)) >= 30:
 		elif len(json.loads(req.content)) >= 30:
 			pageNumber += 1
 			pageNumber += 1
 
 
-	print jsonList
+	# 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
+			
 	'''
 	'''
-	while True:
-		req = requests.get(API_USERS_URL + '/repos' + '?page=' + str(pageNumber) + '&client_id=2404a1e21aebd902f6db' + '&client_secret=3da44769d4b7c9465fa4c812669148a163607c23')
-		#jsonList.append(json.loads(req.content))
-		for data in req.content:
-			for datum in data:
-				if len(datum) < 30:
-					print 'hello'
-					break
-				elif len(datum) >= 30:
-					pageNumber += 1
-					urls.append(API_USERS_URL + '/repos' + '?page=' + str(pageNumber) + '&client_id=2404a1e21aebd902f6db' + '&client_secret=3da44769d4b7c9465fa4c812669148a163607c23')
+	data = {}
+	if datum['author']['login'] == 'DrkSephy':
+		data['author'] = datum['author']['login']
+		data['total'] = datum['total']
+		parsedData.append(data)
 	'''
 	'''
-	#print urls
-	
-	return repositories
 
 
+
+	#print len(jsonList)
+	#print parsedData
+		
 	
 	
-	
+
+

+ 2 - 1
hackathon_starter/hackathon/views.py

@@ -5,7 +5,7 @@ from django.template import RequestContext, loader
 from django.contrib.auth import authenticate, login
 from django.contrib.auth import authenticate, login
 from django.http import HttpResponse, HttpResponseRedirect
 from django.http import HttpResponse, HttpResponseRedirect
 from scripts.steam import gamesPulling, steamIDPulling 
 from scripts.steam import gamesPulling, steamIDPulling 
-from scripts.github import getUserData, getUserRepositories
+from scripts.github import getUserData, getUserRepositories, getTopContributedRepositories
 
 
 
 
 def index(request):
 def index(request):
@@ -119,6 +119,7 @@ def steam(request):
 def github(request):
 def github(request):
     userData = getUserData()
     userData = getUserData()
     repositories = getUserRepositories()
     repositories = getUserRepositories()
+    list = getTopContributedRepositories(repositories)
     # print repositories
     # print repositories
     return render(request, 'hackathon/github.html', { 'data': userData })
     return render(request, 'hackathon/github.html', { 'data': userData })