-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgithub_project.py
103 lines (76 loc) · 2.37 KB
/
github_project.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import config
import requests
import json
import argparse
from urllib.parse import urlparse
from urllib.parse import urljoin
#---------
def connect_github(user):
token = config.gh_api_key
gh_session = requests.Session()
gh_session.auth = (user, token)
return gh_session
#---------
def get_languages(user):
repos_url = 'https://api.github.com/user/repos'
gh_session = connect_github(user)
repos = json.loads(gh_session.get(repos_url).text)
repo_language = []
for repo in repos:
json_format = json.dumps(repo,indent=4)
repo_language.append(repo['language'])
return repo_language
#---------
def get_fav_language(user_name):
languages = get_languages(user_name)
counter = 0
num = languages[0]
for i in languages:
prog_languages = languages.count(i)
if(prog_languages>counter):
counter = prog_languages
pl = i
print('Your language of choice is:',pl)
return pl
#----------
def query_params(l='python', sort_key='updated', order='desc'):
return dict(q=f'language:{l}',sort = sort_key, order=order)
def get_repos(user):
search_language = get_fav_language(user)
url = 'https://api.github.com/search/repositories'
get_repos_url = requests.get(url,params=query_params(l=search_language))
repos_url = get_repos_url
return repos_url
# a = url_construction('repoZTrees')
# print(a)
#--------
def fetch_repos(user):
repos_url = get_repos(user)
repos = repos_url.json()
return repos
def recommend_project(user):
project_name = []
repos = fetch_repos(user)
for project in repos['items']:
json_format = json.dumps(project,indent=4)
project_name.append(project['full_name'])
project_names = []
for i in project_name:
project_names.append(i)
return project_names
#a = recommend_project('repoZTrees')
#print(a)
#---------
def arg_parse():
parser = argparse.ArgumentParser()
parser.add_argument("-u","--user", help="Enter your GitHub username.")
args = parser.parse_args()
return args.user
if __name__ == "__main__":
user_name = arg_parse()
rec_projects = recommend_project(user_name)
print('\n')
print("Repositories Committed Recently")
print('\n')
for i in rec_projects:
print("GitHub Username/Repository Name: {} \n".format(i))