-
Notifications
You must be signed in to change notification settings - Fork 0
/
followers.py
81 lines (71 loc) · 2.51 KB
/
followers.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
69
70
71
72
73
74
75
76
77
78
79
80
81
import requests
import json
orgUser = {}
clientID = "092a70548af705e5aba0"
clientSecret = "ff70fa89e4e7740d097d6ba14420d5ee875259e9"
reqURL = "?client_id="+clientID+"&client_secret="+clientSecret
Orgs = {}
def clusterOrg(user):
queue = [user]
location = ""
usersDone = []
while queue:
user = queue.pop(0)
req = requests.get("https://api.github.com/users/"+user+reqURL)
user = req.json()
print user["location"], location
if user["company"] not in Orgs:
Orgs[user["company"]] = []
if user["login"] not in Orgs[user["company"]]:
Orgs[user["company"]].append(user["login"])
if user["location"] in Orgs:
if user["login"] not in Orgs[user["location"]]:
Orgs[user["location"]].append(user["login"])
r = requests.get(user["followers_url"]+reqURL)
print user["followers_url"]+reqURL
r = r.json()
target = open('orgs.txt', 'w')
target.write(str(Orgs))
print Orgs
for follower in r:#user["followers"]:
# print follower
if follower["login"] not in usersDone:
usersDone.append(follower["login"])
# checkFollowers(follower["login"],org,location)
queue.append(follower["login"])
def checkFollowers(user,org, location):
queue = [user,'arkokoley']
usersDone = []
while queue:
user = queue.pop(0)
req = requests.get("https://api.github.com/users/"+user+reqURL)
user = req.json()
print user["location"], location
if user["location"]:
sa = set(location.replace(',','').split())
sb = set(user["location"].replace(',','').split())
s = sa.intersection(sb)
if not s:
continue
else:
location = ' '.join(sa.union(sb))
if(user["location"] == org):
orgUser[user["login"]] = True;
if(user["company"] == org):
orgUser[user["login"]] = True;
r = requests.get(user["followers_url"]+reqURL)
print user["followers_url"]+reqURL
r = r.json()
target = open('users.txt', 'w')
target.write(str(orgUser))
print orgUser
for follower in r:#user["followers"]:
# print follower
if follower["login"] not in usersDone:
usersDone.append(follower["login"])
# checkFollowers(follower["login"],org,location)
queue.append(follower["login"])
# usersDone.append("suprgyabhushan")
# checkFollowers("suprgyabhushan","IIIT Bangalore","Bangalore, India")
clusterOrg('suprgyabhushan')
print orgUser