github.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. '''
  2. Module github.py contains a handful of methods
  3. for interacting with Github data.
  4. '''
  5. import requests
  6. import simplejson as json
  7. ########################
  8. # GITHUB API CONSTANTS #
  9. ########################
  10. API_BASE_URL = 'https://api.github.com/'
  11. API_USERS_URL = API_BASE_URL + 'users/DrkSephy' + '?client_id=2404a1e21aebd902f6db' + '&client_secret=3da44769d4b7c9465fa4c812669148a163607c23'
  12. # Endpoint to get statistics in a repository
  13. # https://api.github.com/repos/DrkSephy/WaterEmblem/stats/contributors
  14. # https://api.github.com/repos/:user/:repo/stats/contributors
  15. def getUserData():
  16. req = requests.get(API_USERS_URL)
  17. jsonList = []
  18. jsonList.append(json.loads(req.content))
  19. parsedData = []
  20. userData = {}
  21. for data in jsonList:
  22. userData['name'] = data['name']
  23. userData['blog'] = data['blog']
  24. userData['email'] = data['email']
  25. userData['public_gists'] = data['public_gists']
  26. userData['public_repos'] = data['public_repos']
  27. userData['avatar_url'] = data['avatar_url']
  28. userData['followers'] = data['followers']
  29. userData['following'] = data['following']
  30. parsedData.append(userData)
  31. return parsedData
  32. def getUserRepositories():
  33. # Which page number of data are we looking at?
  34. pageNumber = 1
  35. # List of all our json
  36. jsonList = []
  37. # List of all repositories
  38. repositories = []
  39. # IDEA: Repeatedly loop over urls and check if the content has less than 30 entries.
  40. # If it does, then we have iterated over all the data. Time to parse it.
  41. while True:
  42. req = requests.get('https://api.github.com/users/DrkSephy/repos?page=' + str(pageNumber) + '&client_id=2404a1e21aebd902f6db&client_secret=3da44769d4b7c9465fa4c812669148a163607c23')
  43. jsonList.append(json.loads(req.content))
  44. if len(json.loads(req.content)) < 30:
  45. break
  46. elif len(json.loads(req.content)) >= 30:
  47. pageNumber += 1
  48. print jsonList
  49. '''
  50. while True:
  51. req = requests.get(API_USERS_URL + '/repos' + '?page=' + str(pageNumber) + '&client_id=2404a1e21aebd902f6db' + '&client_secret=3da44769d4b7c9465fa4c812669148a163607c23')
  52. #jsonList.append(json.loads(req.content))
  53. for data in req.content:
  54. for datum in data:
  55. if len(datum) < 30:
  56. print 'hello'
  57. break
  58. elif len(datum) >= 30:
  59. pageNumber += 1
  60. urls.append(API_USERS_URL + '/repos' + '?page=' + str(pageNumber) + '&client_id=2404a1e21aebd902f6db' + '&client_secret=3da44769d4b7c9465fa4c812669148a163607c23')
  61. '''
  62. #print urls
  63. return repositories