github.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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'
  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. req = requests.get(API_USERS_URL + '/repos')
  34. jsonList = []
  35. jsonList.append(json.loads(req.content))
  36. repositories = []
  37. for data in jsonList:
  38. for datum in data:
  39. repositories.append(datum['name'])
  40. return repositories