-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_repo_list.py
47 lines (34 loc) · 1.14 KB
/
get_repo_list.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
"""
Get top-100 repositories sorted by stars, and sort by size
"""
import utils
from config import token
import json
path_top_100_stars = 'spotbugs-experiment/top-100-stars.json'
path_sort_size = 'spotbugs-experiment/sort-size.json'
def get_top_100_stars():
query = 'https://api.github.com/search/repositories?q=language:java&page=1&per_page=100'
resp = utils.send(query, token, 3)
if not resp:
print("No response")
exit(1)
jresp = resp.json()
utils.create_missing_dirs(path_top_100_stars)
with open(path_top_100_stars, 'w') as out:
json.dump(jresp, out)
def sort_by_size():
with open(path_top_100_stars, 'r') as f:
jlist = json.load(f)
jlist = jlist['items']
sorted_list = sorted(jlist, key=lambda k: k.get('size', 0))
simple_list = [{
'html_url': repo['html_url'],
'stargazers_count': repo['stargazers_count'],
'size': repo['size']
} for repo in sorted_list]
utils.create_missing_dirs(path_sort_size)
with open(path_sort_size, 'w') as out:
json.dump(simple_list, out)
if __name__ == '__main__':
get_top_100_stars()
sort_by_size()