-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathlist2md.py
More file actions
77 lines (56 loc) · 2.84 KB
/
list2md.py
File metadata and controls
77 lines (56 loc) · 2.84 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
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
from datetime import datetime
import json
import requests
head = '''# Top Python Web Frameworks
A list of popular github projects related to Python web framework (ranked by stars automatically)
Please update **list.txt** (via Pull Request)
| Project Name | Stars | Forks | Open Issues | Description | Last Commit |
| ------------ | ----- | ----- | ----------- | ----------- | ----------- |
'''
tail = '\n*Last Automatic Update: {}*'
warning = "⚠️ No longer maintained ⚠️ "
deprecated_repos = list()
repos = list()
def main():
access_token = get_access_token()
with open('list.txt', 'r') as f:
for url in f.readlines():
url = url.strip()
if url.startswith('https://github.com/'):
repo_api = 'https://api.github.com/repos/{}?access_token={}'.format(url[19:], access_token)
print(repo_api)
r = requests.get(repo_api)
if r.status_code != 200:
raise ValueError('Can not retrieve from {}'.format(url))
repo = json.loads(r.content)
commit_api = 'https://api.github.com/repos/{}/commits/{}?access_token={}'.format(url[19:], repo['default_branch'], access_token)
print(repo_api)
r = requests.get(commit_api)
if r.status_code != 200:
raise ValueError('Can not retrieve from {}'.format(url))
commit = json.loads(r.content)
repo['last_commit_date'] = commit['commit']['committer']['date']
repos.append(repo)
repos.sort(key=lambda r: r['stargazers_count'], reverse=True)
save_ranking(repos)
def get_access_token():
with open('access_token.txt', 'r') as f:
return f.read().strip()
def save_ranking(repos):
with open('README.md', 'w') as f:
f.write(head)
for repo in repos:
if is_deprecated(repo['url']):
repo['description'] = warning + repo['description']
f.write('| [{}]({}) | {} | {} | {} | {} | {} |\n'.format(repo['name'],
repo['html_url'],
repo['stargazers_count'],
repo['forks_count'],
repo['open_issues_count'],
repo['description'],
datetime.strptime(repo['last_commit_date'], '%Y-%m-%dT%H:%M:%SZ').strftime('%Y-%m-%d %H:%M:%S')))
f.write(tail.format(datetime.now().strftime('%Y-%m-%dT%H:%M:%S%Z')))
def is_deprecated(repo_url):
return repo_url in deprecated_repos
if __name__ == '__main__':
main()