Skip to content

Commit

Permalink
Add custom project list feature to search term script
Browse files Browse the repository at this point in the history
  • Loading branch information
mrthankyou committed Feb 17, 2021
1 parent ca2bbc6 commit 69543fb
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
34 changes: 27 additions & 7 deletions follow_repos_by_search_term.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,32 @@
from typing import List
from lgtm import LGTMSite

import utils.cacher
import utils.github_dates
import utils.github_api

import sys
import time

def save_project_to_lgtm(site: 'LGTMSite', repo_name: str):
def save_project_to_lgtm(site: 'LGTMSite', repo_name: str) -> dict:
print("About to save: " + 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
site.follow_repository(repo_url)
project = site.follow_repository(repo_url)
print("Saved the project: " + repo_name)
return project

def find_and_save_projects_to_lgtm(language: str, search_term: str):
def find_and_save_projects_to_lgtm(language: str, search_term: str) -> List[str]:
github = utils.github_api.create()
site = LGTMSite.create_from_file()

saved_project_ids: List[str] = []
for date_range in utils.github_dates.generate_dates():
repos = github.search_repositories(query=f'language:{language} fork:false created:{date_range} {search_term}')

print(f'language:{language} fork:false created:{date_range} {search_term}')
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
Expand All @@ -32,7 +35,18 @@ def find_and_save_projects_to_lgtm(language: str, search_term: str):
if repo.archived or repo.fork:
continue

save_project_to_lgtm(site, repo.full_name)
saved_project = save_project_to_lgtm(site, repo.full_name)
print('--------------------')
print('--------------------')
print('--------------------')
print(saved_project)
print('--------------------')
print('--------------------')
print('--------------------')
saved_project_id = saved_project['realProject'][0]['key']
saved_project_ids.append(saved_project_id)

return saved_project_ids

if len(sys.argv) < 3:
print("Please make sure you provided a language and search term")
Expand All @@ -42,4 +56,10 @@ def find_and_save_projects_to_lgtm(language: str, search_term: str):
search_term = sys.argv[2]

print(f'Following repos for the {language} language that contain the \'{search_term}\' search term.')
find_and_save_projects_to_lgtm(language, search_term)
saved_project_ids = find_and_save_projects_to_lgtm(language, search_term)

# If the user provided a second arg then they want to create a custom list.
if len(sys.argv) <= 4:
# print
custom_list_name = sys.argv[3]
utils.cacher.write_project_ids_to_file(saved_project_ids, custom_list_name)
5 changes: 2 additions & 3 deletions follow_top_repos_by_star_count.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

import utils.github_dates
import utils.github_api
import utils.cacher
import utils.cacher
import sys
import time

Expand Down Expand Up @@ -75,8 +75,7 @@ def find_and_save_projects_to_lgtm(language: str) -> List[str]:

print('Following the top repos for %s' % language)
saved_project_ids = find_and_save_projects_to_lgtm(language)
print("saved proejct ids")
print(saved_project_ids)

# If the user provided a second arg then they want to create a custom list.
if len(sys.argv) <= 3:
# print
Expand Down

0 comments on commit 69543fb

Please sign in to comment.