def get_gh_data(): gh_access_token = request.cookies.get('gh_access_token') gh = GitHub(access_token=gh_access_token) user_id = gh.user().get()['login'] page = 1 events = gh.users(user_id).events().get(page=page) while True: page += 1 new_events = gh.users(user_id).events().get(page=page) if len(new_events) > 0: events.extend(new_events) else: break created_ats = [e['created_at'][:-1] for e in events] timestamps = [] for ca in created_ats: ts = time.strptime(ca, "%Y-%m-%dT%H:%M:%S") timestamps.append((ts.tm_hour * 60 + ts.tm_min -300)%1440) print("GH: " + str(len(timestamps))) return json.dumps(timestamps)
class GitHubScooper(object): def __init__(self, type='GitHub', user=None, token=None): self.user = user self.gh = GitHub(access_token=token) def scoop(self): result = [] events = self.gh.users(self.user).events.public.get() for event in events: hash = sha256() hash.update(event['id'].encode()) result.append(dict( checksum=hash.hexdigest(), headline='{} event to repo {}'.format( event['type'], event['repo']['name']), content='contentfoo', pub_date=datetime.strptime( event['created_at'], '%Y-%m-%dT%H:%M:%SZ'))) return result
from github import GitHub gh = GitHub() user = gh.users('stevesun112').get() #print( user ) commit = gh.repos('imsure', 'hello-antares').commits('083a8604a73dcb5eda83a5bdd6638a93cfa60045').get() #print( commit[ 'html_url' ] ) search = gh.search.code.get(q="addClass in:file language:js repo:jquery/jquery") #print( search ) search = gh.search.code.get(q="create_table in:file language:py repo:imsure/hello-antares") #print( search[ 'items' ][0][ 'html_url' ] ) user = gh.users('AzNOAOTares').get() print( user ) commit = gh.repos('AzNOAOTares', 'antares-docs').commits('ee22aff520fba4e69971c9ac86a383e0b2374bb6').get() print( commit[ 'html_url' ] ) # search = gh.search.code.get(q="addClass in:file language:js repo:jquery/jquery") #print( search ) search = gh.search.code.get(q="maketitle in:file language:tex repo:AzNOAOTares/antares-docs") print( search[ 'items' ][0][ 'html_url' ] ) user = gh.users('AzNOAOTares').get() print( user ) commit = gh.repos('AzNOAOTares', 'architecture').commits('93d4c7d2e6d6950dbeebff0de9c33941ecf3d109').get() print( commit[ 'html_url' ] ) # search = gh.search.code.get(q="addClass in:file language:js repo:jquery/jquery") #print( search ) #search = gh.search.code.get(q="maketitle in:file language:tex repo:AzNOAOTares/antares-docs") #print( search[ 'items' ][0][ 'html_url' ] )
from github import GitHub if False: gh = GitHub("Test") res = gh.users('octocats').get() print res else: from twisted.internet import threads, reactor, defer gh = GitHub("Test", async=True) @defer.inlineCallbacks def f(): print "Async" res = yield gh.users('octocats').get() print res reactor.stop() f() reactor.run()