-
Notifications
You must be signed in to change notification settings - Fork 4
/
gitloader.py
53 lines (44 loc) · 1.29 KB
/
gitloader.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
import os
import json
import time
import getpass
import itertools
username = input("Github username? ")
password = getpass.getpass("Github password? ")
allrepos = {}
totalcount = 0
for page in itertools.count(1):
if page == 11:
print("interrupting due to search restrictions")
break
penalty = 10
while True:
os.system("curl -su {}:{} 'https://api.github.com/search/code?q=filename:Chart.yaml&per_page=100&page={}' -o gitloader.json".format(username, password, page))
time.sleep(4)
results = json.load(open("gitloader.json"))
if not "documentation_url" in results:
break
print("penalty: {}s...".format(penalty))
time.sleep(penalty)
penalty *= 2
continue
if not totalcount:
totalcount = results["total_count"]
if page * 100 > totalcount:
break
repos = set()
for item in results["items"]:
repo = item["repository"]["full_name"]
if repo in allrepos:
allrepos[repo] += 1
else:
allrepos[repo] = 1
print("loading: {} of {}... ({} unique results)".format(page * 100, totalcount, len(allrepos)))
print("Statistics:")
print(" total Helm charts (Chart.yaml): ", results["total_count"])
print(" total repositories:", len(allrepos))
f = open("gitloader.csv", "w")
print("#repo,chartcount", file=f)
for repo in allrepos:
print("{},{}".format(repo, allrepos[repo]), file=f)
f.close()