-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfetch_data.py
More file actions
134 lines (101 loc) · 4.02 KB
/
fetch_data.py
File metadata and controls
134 lines (101 loc) · 4.02 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
from github import Github
# Specify your own access token here
ACCESS_TOKEN = ''
client = Github(ACCESS_TOKEN, per_page=100)
# Specify a username and repository of interest for that user.
USER = 'ahmadawais'
REPO = 'hacktoberfest'
user = client.get_user(USER)
repo = user.get_repo(REPO)
import networkx as nx
g_stargazers = nx.DiGraph()
g_stargazers.add_node(repo.name + '(repo)', type='repo', lang=repo.language, owner=user.login)
stargazers = [ s for s in repo.get_stargazers() ]
print ("Number of stargazers", len(stargazers))
for sg in stargazers:
g_stargazers.add_node(sg.login + '(user)', type='user')
g_stargazers.add_edge(sg.login + '(user)', repo.name + '(repo)', type='gazes')
%matplotlib inline
import matplotlib.pyplot as plt
plt.figure(figsize=(15,10))
nx.draw(g_stargazers, with_labels=True, node_size=30)
plt.show()
import networkx as nx
g_forks = nx.DiGraph()
g_forks.add_node(repo.name + '(repo)', type='repo', lang=repo.language, owner=user.login)
# Get a list of people who have bookmarked the repo.
# Since you'll get a lazy iterator back, you have to traverse
# it if you want to get the total number of stargazers.
forks = [ s for s in repo.get_forks() ]
print ("Number of forks", len(forks))
for fork in forks:
g_forks.add_node(fork.full_name , type='user')
g_forks.add_edge(fork.full_name, repo.name + '(repo)', type='forks')
%matplotlib inline
import matplotlib.pyplot as plt
plt.figure(figsize=(15,10))
nx.draw(g_forks, with_labels=True, node_size=1000)
plt.show()
# Specify a username
USER = 'Dhanya-Abhirami'
user = client.get_user(USER)
import networkx as nx
g_followers = nx.Graph()
g_followers.add_node(user.login + '(user)', type='user')
# Get a list of people who have bookmarked the repo.
# Since you'll get a lazy iterator back, you have to traverse
# it if you want to get the total number of stargazers.
followers = [ s for s in user.get_followers() ]
print ("Number of followers", len(followers))
for follower in followers:
g_followers.add_node(follower.login + '(user)', type='user')
g_followers.add_edge(follower.login + '(user)', user.login + '(repo)', type='follows')
%matplotlib inline
import matplotlib.pyplot as plt
plt.figure(figsize=(15,10))
nx.draw(g_followers, with_labels=True, node_size=1)
plt.show()
for follower in followers:
followers_2 = [ s for s in follower.get_followers() ]
for follower_2 in followers_2:
g_followers.add_node(follower_2.login + '(user)', type='user')
g_followers.add_edge(follower_2.login + '(user)', follower.login + '(repo)', type='follows')
%matplotlib inline
import matplotlib.pyplot as plt
plt.figure(figsize=(15,10))
nx.draw(g_followers, with_labels=True, node_size=1)
plt.show()
print (nx.info(g_followers))
from operator import itemgetter
from IPython.display import HTML
from IPython.core.display import display
print ("Degree Centrality")
print (sorted(nx.degree_centrality(g_followers).items(),key=itemgetter(1), reverse=True)[:10])
print ("Betweenness Centrality")
print (sorted(nx.betweenness_centrality(g_followers).items(), key=itemgetter(1), reverse=True)[:10])
print ("Closeness Centrality")
print (sorted(nx.closeness_centrality(g_followers).items(), key=itemgetter(1), reverse=True)[:10])
import operator
pr = nx.pagerank(g_followers)
sorted_x = sorted(pr.items(), key=operator.itemgetter(1),reverse=True)
print(sorted_x[:10])
hub, authority = nx.hits(g_followers)
sorted_hub = sorted(hub.items(), key=operator.itemgetter(1),reverse=True)
print("Most Influential Users based on Hub Score")
print(sorted_hub[:10])
print()
sorted_authority = sorted(authority.items(), key=operator.itemgetter(1),reverse=True)
print("Most Influential Users based on Authority Score")
print(sorted_authority[:10])
from networkx.algorithms.community.centrality import girvan_newman
import itertools
comp = girvan_newman(g_followers)
k = 5
limited = itertools.takewhile(lambda c: len(c) <= k, comp)
print("Number of users in community")
i=1
for communities in limited:
print("\nIteration",i,"\n\n")
i+=1
for c in communities:
print(len(c))