forked from devmanorg/9_github_trending
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub_trending.py
More file actions
42 lines (36 loc) · 1.22 KB
/
Copy pathgithub_trending.py
File metadata and controls
42 lines (36 loc) · 1.22 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
import requests
from datetime import datetime, timedelta
def get_trending_repositories(top_size):
url = 'https://api.github.com/search/repositories'
time_now = datetime.now()
last_week = (time_now - timedelta(days=7)).strftime('%Y-%m-%d')
created_less_than_week_ago = 'created:>={}'.format(last_week)
params = {
'q': created_less_than_week_ago,
'sort': 'stars',
'order': 'desc',
'page': '1',
'per_page': top_size
}
trending_repos = requests.get(url, params=params)
return trending_repos.json()['items']
def get_open_issues_amount(repo_owner, repo_name):
url = 'https://api.github.com/repos/{}/{}/issues'.format(
repo_owner,
repo_name
)
issues = requests.get(url)
return len(issues.json())
if __name__ == '__main__':
top_size = 20
top_github_repos = get_trending_repositories(top_size)
for repo in top_github_repos:
repo_name = repo['name']
repo_owner = repo['owner']['login']
repo_url = repo['url']
print('Name: {}'.format(repo_name))
print('Issues: {}'.format(get_open_issues_amount(
repo_owner,
repo_name
)))
print('Link: {}\n'.format(repo_url))