-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgithubScrapper.py
59 lines (49 loc) · 1.55 KB
/
githubScrapper.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
#!/usr/bin/python
import pycurl
import json;
from io import BytesIO
class gitUser:
gHandle='';
#lists
repos=None; #list of the users repos, stored in a list - check github api for docs
orgs = None
#ints stored for easy access
stargazers=0; ## of stars in all repos
def __init__(self, gHandle=""):
self.gHandle=gHandle;
def getHandle(self):
return self.gHandle
#returns a list of all repos user owns, options are member, owner and all, 2nd param is force update
def getRepos(self, typeOfRepo="all", force=False):
if self.repos is None or force:
buffer = BytesIO()
c = pycurl.Curl()
c.setopt(c.URL, 'https://api.github.com/users/'+self.gHandle+'/repos?type='+typeOfRepo)
c.setopt(c.WRITEDATA, buffer)
c.perform()
c.close()
body = buffer.getvalue()
# Body is a byte string.
# We have to know the encoding in order to print it to a text file
# such as standard output.
self.repos = json.loads(body.decode('iso-8859-1'))
return self.repos
def getOrgs(self):
if self.orgs is None:
buffer = BytesIO()
c = pycurl.Curl()
c.setopt(c.URL, 'https://api.github.com/users/'+self.gHandle+'/orgs')
c.setopt(c.WRITEDATA, buffer)
c.perform()
c.close()
body = buffer.getvalue()
# Body is a byte string.
# We have to know the encoding in order to print it to a text file
# such as standard output.
self.orgs = json.loads(body.decode('iso-8859-1'))
return self.orgs
def getStars(self):
stargazers=0
for x in self.getRepos("owner"):
self.stargazers+=x['stargazers_count']
return self.stargazers