Selaa lähdekoodia

Working on refactoring client secret and client ID

David Leonard 10 vuotta sitten
vanhempi
commit
e9e916191c

+ 10 - 10
hackathon_starter/hackathon/scripts/github.py

@@ -10,13 +10,13 @@ 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'
+API_BASE_URL = 'https://api.github.com/users/DrkSephy'
+#API_USERS_URL = API_BASE_URL + 'users/DrkSephy' + '?client_id=2404a1e21aebd902f6db' + '&client_secret=3da44769d4b7c9465fa4c812669148a163607c23'
 
-def getUserData():
+def getUserData(clientID, clientSecret):
 	'''Get generic Github User data.'''
-
-	req = requests.get(API_USERS_URL)
+	url = API_BASE_URL + clientID + clientSecret
+	req = requests.get(url)
 	jsonList = []
 	jsonList.append(json.loads(req.content))
 	parsedData = []
@@ -35,7 +35,7 @@ def getUserData():
 	return parsedData
 	
 
-def getUserRepositories():
+def getUserRepositories(clientID, clientSecret):
 	'''Get a list of all repositories owned by a User.'''
 
 	# Which page number of data are we looking at?
@@ -64,7 +64,7 @@ def getUserRepositories():
 
 	return repositories
 
-def getForkedRepositories():
+def getForkedRepositories(clientID, clientSecret):
 	'''Get a list of all forked repositories by a user.'''
 	# Which page number of data are we looking at?
 	pageNumber = 1
@@ -97,13 +97,13 @@ def getForkedRepositories():
 
 	return forkedRepositories
 
-def getTopContributedRepositories(repos):
+def getTopContributedRepositories(repos, clientID, clientSecret):
 	'''Get a list of all commits for each repository owned.'''
 
 	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')
+		req = requests.get('https://api.github.com/repos/DrkSephy/' + repo + '/stats/contributors' + clientID + clientSecret)
 		jsonList.append(json.loads(req.content))
 
 	parsedData = []
@@ -133,7 +133,7 @@ def filterCommits(data):
 	return maxCommits
 	
 	
-def getStarGazerCount():
+def getStarGazerCount(clientID, clientSecret):
 	'''Get Stargazer counts for all repositories.'''
 
 	# Which page number of data are we looking at?

+ 6 - 5
hackathon_starter/hackathon/views.py

@@ -7,6 +7,7 @@ from django.http import HttpResponse, HttpResponseRedirect
 from scripts.steam import gamesPulling, steamIDPulling 
 from scripts.github import *
 from scripts.tumblr import *
+from django.conf import settings
 
 
 
@@ -121,19 +122,19 @@ def steam(request):
 def github(request):
     allData = {}
     # Get generic user data
-    userData = getUserData()
+    userData = getUserData(settings.GITHUB_CLIENT_ID, settings.GITHUB_CLIENT_SECRET)
     # Get a list of all the user's repositories
-    repositories = getUserRepositories()
+    repositories = getUserRepositories(settings.GITHUB_CLIENT_ID, settings.GITHUB_CLIENT_SECRET)
     # Get a list of all commit statistics for all repositories
-    list = getTopContributedRepositories(repositories)
+    list = getTopContributedRepositories(repositories, settings.GITHUB_CLIENT_ID, settings.GITHUB_CLIENT_SECRET)
     # Get a list of the top 10 most committed repositories
     filtered = filterCommits(list)
     # Get list of all stargazer counts for all repositories
-    stargazers = getStarGazerCount()
+    stargazers = getStarGazerCount(settings.GITHUB_CLIENT_ID, settings.GITHUB_CLIENT_SECRET)
     # Return list of top 10 stargazed repositories
     filteredStargazers = filterStarGazerCount(stargazers)
     # Get list of forked repositories
-    forkedRepos = getForkedRepositories()
+    forkedRepos = getForkedRepositories(settings.GITHUB_CLIENT_ID, settings.GITHUB_CLIENT_SECRET)
     
     # Store data into a dictionary for rendering
     allData['userData'] = userData

+ 7 - 0
hackathon_starter/hackathon_starter/settings.py

@@ -88,3 +88,10 @@ STATIC_URL = '/static/'
 
 TEMPLATE_DIRS = [os.path.join(BASE_DIR, 'templates')]
 
+############
+#   KEYS   #
+############
+
+GITHUB_CLIENT_ID = '?client_id=2404a1e21aebd902f6db'
+GITHUB_CLIENT_SECRET = '&client_secret=3da44769d4b7c9465fa4c812669148a163607c23'
+