def search_github_trending( language=None, spoken_language=None, order="desc", stars=">=10", date_range=None ): """ Returns trending repositories from github trending page """ if date_range: gtrending_repo_list = fetch_repos( language, spoken_language, date_range_map[date_range] ) else: gtrending_repo_list = fetch_repos(language, spoken_language) repositories = [] for gtrending_repo in gtrending_repo_list: repo_dict = convert_repo_dict(gtrending_repo) repo_dict["date_range"] = ( str(repo_dict["date_range"]) + " stars " + date_range.replace("-", " ") if date_range else None ) repo_dict["watchers_count"] = -1 # watchers count not available # filter by number of stars num = [int(s) for s in re.findall(r"\d+", stars)][0] if ( ("<" in stars and repo_dict["stargazers_count"] < num) or ("<=" in stars and repo_dict["stargazers_count"] <= num) or (">" in stars and repo_dict["stargazers_count"] > num) or (">=" in stars and repo_dict["stargazers_count"] >= num) ): repositories.append(repo_dict) if order == "asc": return sorted(repositories, key=lambda repo: repo["stargazers_count"]) return sorted(repositories, key=lambda repo: repo["stargazers_count"], reverse=True)
def main(): count = get_count() verify_count() repos = fetch_repos('python')[0:int(count)] repo_store.store_repos(repos) calc_repos_security_score(repos) print_repos_in_list(repos)
def test_incorrect_values(): with pytest.raises(ValueError): fetch_repos("false_language") with pytest.raises(ValueError): fetch_repos("python", "false") with pytest.raises(ValueError): fetch_repos("python", "en", "annually")
def test_language(): res = fetch_repos(language="python") basic_assertions(res, "python") res = fetch_repos(language="javascript") basic_assertions(res, "javascript")
def test_all(): res = fetch_repos() basic_assertions(res)