-
Notifications
You must be signed in to change notification settings - Fork 1
/
search_repos.py
34 lines (27 loc) · 976 Bytes
/
search_repos.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
import requests
import sys
import webbrowser
GITHUB_URL = "https://api.github.com/search/repositories?q={query_string}&sort=stars"
class CustomException(Exception):
pass
def get_repo_link(repo_name, language):
query_string = repo_name
if language:
query_string = "+".join([repo_name, language])
try:
response = requests.get(GITHUB_URL.format(query_string=query_string)).json()
return response["items"][0]['html_url']
except requests.exceptions.BaseHTTPError:
raise CustomException("Error in reaching github some error occurred")
def main(repo_name, language):
try:
repo_link = get_repo_link(repo_name, language)
webbrowser.open_new_tab(repo_link)
except webbrowser.Error:
raise CustomException("Error in opening browser")
if __name__ == "__main__":
repo_name = sys.argv[1]
language = None
if len(sys.argv) == 3:
language = sys.argv[2]
main(repo_name, language)