Advertisement
Guest User

Untitled

a guest
Aug 11th, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. import json
  2. from restkit import Resource, BasicAuth, Connection, request
  3. from socketpool import ConnectionPool
  4. import sys
  5.  
  6. pool = ConnectionPool(factory=Connection)
  7. serverurl="https://api.github.com"
  8.  
  9. # Pass the username and password to the command line as arguements
  10. user = "sudonhim"
  11. password = "buzzbuzz434"
  12. auth=BasicAuth(user, password)
  13.  
  14. # Use your basic auth to request a token
  15. # This is just an example from http://developer.github.com/v3/
  16. authreqdata = { "scopes": [ "public_repo" ], "note": "admin script" }
  17. resource = Resource('https://api.github.com/authorizations',
  18. pool=pool, filters=[auth])
  19. response = resource.post(headers={ "Content-Type": "application/json" },
  20. payload=json.dumps(authreqdata))
  21. token = json.loads(response.body_string())['token']
  22.  
  23. """
  24. Once you have a token, you can pass that in the Authorization header
  25. You can store this in a cache and throw away the user/password
  26. This is just an example query. See http://developer.github.com/v3/
  27. for more about the url structure
  28. """
  29.  
  30.  
  31. link = "https://api.github.com/orgs/google/members?page="
  32. pagenum = 1
  33. arr = "[\n"
  34. while True:
  35. resource = Resource(link + str(pagenum), pool=pool)
  36. headers = {'Content-Type' : 'application/json' }
  37. headers['Authorization'] = 'token %s' % token
  38. response = resource.get(headers = headers)
  39. data = response.body_string()
  40. requests.get(link + str(pagenum)).text
  41. if (len(data) < 100):
  42. break
  43. arr += data[1:-1] + ",\n"
  44. print("Got page number " + str(pagenum))
  45. pagenum += 1
  46. print(data[:100]+"...")
  47. arr += "]\n"
  48. f = open("out.txt", 'w')
  49. f.write(arr)
  50. f.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement