-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgithub_follower.py
79 lines (69 loc) · 2.25 KB
/
github_follower.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
# -*- coding: utf-8 -*-
from github import Github, StatsCommitActivity
from multiprocessing import Pool, cpu_count, Lock
import pandas as pd
import csv
import networkx as nx
# or using an access token
GIT = Github("81bb10423c837b5a6d517b25117a7a95a7ec444a")
list_all_following=[]
column_name=['User','Following']
def _task(list_following,i):
"""
Arguments:
NamedUser {[class]} -- [github.NamedUser.NamedUser]
"""
i += 1
print(i)
if i==2:
return
for following in list_following:
login = following.login
list_following_fo = following.get_following()
for following_fo in list_following_fo:
list_user=[]
list_user.append(login)
list_user.append(following_fo.login)
list_all_following.append(list_user)
print(list_all_following)
_task(list_following_fo,i)
def _print_user_profile(NamedUser):
"""[print user profile]
Arguments:
user {[class]} -- [github.NamedUser.NamedUser]
"""
print('--------------------------------')
print(NamedUser.created_at.year)
print('login :' + NamedUser.login)
print('name :' + NamedUser.name)
print('type :' + NamedUser.type)
print('company :' + NamedUser.company)
print('location :' + NamedUser.location)
print('contributions:' + str(NamedUser.contributions))
print('followers :' + str(NamedUser.followers))
print('followers_url:' + NamedUser.followers_url)
print('--------------------------------')
def get_all_followings(user_name):
"""[get all followers]
Arguments:
user_name {[string]} -- [user to analysis]
"""
center_user = GIT.get_user(user_name)
_print_user_profile(center_user)
login = center_user.login
list_following = center_user.get_following()
for following in list_following:
list_user=[]
list_user.append(login)
list_user.append(following.login)
list_all_following.append(list_user)
print(list_all_following)
i=0
_task(list_following,i)
df = pd.DataFrame(data=list_all_following,columns = column_name)
df.to_csv('following_graph.csv')
print('-----end-----')
def main():
get_all_followings('wangshub')
if __name__ == '__main__':
main()