/
testPyGithub.py
69 lines (44 loc) · 1.22 KB
/
testPyGithub.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
from github import Github
import os
mypw = os.environ['GITPASSWD']
g = Github('gauthamnair', mypw)
ratelimit = g.get_rate_limit()
print ratelimit.rate.limit
hadley = g.get_user('hadley')
repos = {repo.name:repo for repo in hadley.get_repos()}
plyr = repos['plyr']
print plyr.created_at
hadleyAsOwner = plyr.owner
print hadleyAsOwner.name
print (hadley == hadleyAsOwner)
commits = list(plyr.get_commits())
# using g.get_rate_limit().rate.remaining
# can see that each pagination counts as an api call.
print len(commits)
# says 715
# Exactly matches what Github website says!
# try doing it by hand:
import requests
plyrCommitsURL = r'https://api.github.com/repos/hadley/plyr/commits'
r = requests.get(plyrCommitsURL)
asjson = r.json()
print len(asjson)
#says 30: probably needs pagination
print r.headers['link']
# Yes - best to use pygithub :)
# Try to get a list of repositories:
qstr = 'language:R created:"<= 2011-01-01"'
sr = g.search_repositories(query=qstr)
print sr.totalCount
# gives 354, same as the github website
p0 = sr.get_page(0)
print len(p0)
#30
print len(sr.get_page(13))
#0
firstRepo = p0[0]
print type(firstRepo)
# github Repository
print firstRepo.owner.login
print firstRepo.full_name
print firstRepo.fork