Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import json
- from restkit import Resource, BasicAuth, Connection, request
- from socketpool import ConnectionPool
- import sys
- pool = ConnectionPool(factory=Connection)
- serverurl="https://api.github.com"
- # Pass the username and password to the command line as arguements
- user = "sudonhim"
- password = "buzzbuzz434"
- auth=BasicAuth(user, password)
- # Use your basic auth to request a token
- # This is just an example from http://developer.github.com/v3/
- authreqdata = { "scopes": [ "public_repo" ], "note": "admin script" }
- resource = Resource('https://api.github.com/authorizations',
- pool=pool, filters=[auth])
- response = resource.post(headers={ "Content-Type": "application/json" },
- payload=json.dumps(authreqdata))
- token = json.loads(response.body_string())['token']
- """
- Once you have a token, you can pass that in the Authorization header
- You can store this in a cache and throw away the user/password
- This is just an example query. See http://developer.github.com/v3/
- for more about the url structure
- """
- link = "https://api.github.com/orgs/google/members?page="
- pagenum = 1
- arr = "[\n"
- while True:
- resource = Resource(link + str(pagenum), pool=pool)
- headers = {'Content-Type' : 'application/json' }
- headers['Authorization'] = 'token %s' % token
- response = resource.get(headers = headers)
- data = response.body_string()
- requests.get(link + str(pagenum)).text
- if (len(data) < 100):
- break
- arr += data[1:-1] + ",\n"
- print("Got page number " + str(pagenum))
- pagenum += 1
- print(data[:100]+"...")
- arr += "]\n"
- f = open("out.txt", 'w')
- f.write(arr)
- f.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement