-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathfollow_top_repos_by_star_count.py
More file actions
60 lines (45 loc) · 2.11 KB
/
follow_top_repos_by_star_count.py
File metadata and controls
60 lines (45 loc) · 2.11 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
from typing import List
from lgtm import LGTMSite, LGTMDataFilters
import utils.github_dates
import utils.github_api
import utils.cacher
import sys
import time
def save_project_to_lgtm(site: 'LGTMSite', repo_name: str) -> dict:
print("Adding: " + repo_name)
# Another throttle. Considering we are sending a request to Github
# owned properties twice in a small time-frame, I would prefer for
# this to be here.
time.sleep(1)
repo_url: str = 'https://github.com/' + repo_name
project = site.follow_repository(repo_url)
print("Saved the project: " + repo_name)
return project
def find_and_save_projects_to_lgtm(language: str) -> List[str]:
github = utils.github_api.create()
site = LGTMSite.create_from_file()
saved_project_data: List[str] = []
for date_range in utils.github_dates.generate_dates():
repos = github.search_repositories(query=f'stars:>500 created:{date_range} fork:false sort:stars language:{language}')
for repo in repos:
# Github has rate limiting in place hence why we add a sleep here. More info can be found here:
# https://docs.github.com/rest/overview/resources-in-the-rest-api#rate-limiting
time.sleep(1)
if repo.archived or repo.fork:
continue
saved_project = save_project_to_lgtm(site, repo.full_name)
simple_project = LGTMDataFilters.build_simple_project(saved_project)
if simple_project.is_valid_project:
saved_data = f'{simple_project.display_name},{simple_project.key},{simple_project.project_type}'
saved_project_data.append(saved_data)
return saved_project_data
if len(sys.argv) < 2:
print("Please provide a language you want to search")
exit
language = sys.argv[1].capitalize()
print('Following the top repos for %s' % language)
saved_project_data = find_and_save_projects_to_lgtm(language)
# If the user provided a second arg then they want to create a custom list.
if len(sys.argv) <= 3:
custom_list_name = sys.argv[2]
utils.cacher.write_project_data_to_file(saved_project_data, custom_list_name)