forked from UT-OSPO/institutional-innovation-grapher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgithub_repo_getter.py
54 lines (46 loc) · 1.9 KB
/
github_repo_getter.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
import json
import csv
from datetime import datetime
from github import Github, Auth
from tqdm import tqdm
with open(".env") as envfile:
config = json.loads(envfile.read())
auth = Auth.Token(config['githubtoken'])
g = Github(auth=auth)
repolanguagelist = []
repolicenselist = []
repostargazerlist = []
repowatcherlist = []
repoforklist = []
finalgithubrepodetailscsvrows = []
githubrepodetailscsvcolumns = ['name','full_name','html_url','description','fork','created_at','updated_at','size','stargazers_count','watchers_count','language','forks_count','archived','open_issues_count','allow_forking','topics','forks','visibility','open_issues']
username_file = open("github_usernames.txt", "r")
for username in username_file:
username = username.strip()
print("Getting repos for %s..." % username)
try:
user = g.get_user(username)
except:
print("User %s does not exist" % username)
continue
repos = user.get_repos()
for i in tqdm(range(repos.totalCount)):
repo = repos[i]
repocsvrow = []
repocsvrow.append(username)
for att in githubrepodetailscsvcolumns:
tmp = getattr(repo, att)
if att == 'description' and tmp is not None:
tmp = tmp.encode('ascii', 'ignore').decode()
repocsvrow.append(tmp)
repocsvrow.append(getattr(repo.license, 'name', 'None'))
repocsvrow.append(json.dumps(repo.get_languages()))
finalgithubrepodetailscsvrows.append(repocsvrow)
githubrepodetailscsvcolumns.insert(0, 'owner')
githubrepodetailscsvcolumns.extend(['license', 'language_lines'])
with open("outputs/repos_%s.csv" % datetime.now().strftime("%Y-%m-%d"), "w", newline="") as opencsv:
csvwriter = csv.writer(opencsv)
csvwriter.writerow(githubrepodetailscsvcolumns)
for i, csvrow in enumerate(finalgithubrepodetailscsvrows):
csvwriter.writerow(csvrow)
username_file.close()