-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist2md.py
80 lines (57 loc) · 2.81 KB
/
list2md.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
from datetime import datetime
import json
import requests
head = '''# Top Fullstack Frameworks
A list of popular github projects related to Fullstack web frameworks (ranked by stars automatically)
'''
tail = '\n*Last Automatic Update: {}*'
warning = "\n⚠️ No longer maintained ⚠️\n\n"
deprecated_repos = []
repos = list()
def main():
access_token = get_access_token()
with open('list.txt', 'r') as f:
for url in f.readlines():
url, name = url.strip().split(' ')
if url.startswith('https://github.com/'):
repo_api = 'https://api.github.com/repos/{}'.format(url[19:])
r = requests.get(repo_api, headers={'Authorization': 'token {}'.format(access_token)})
if r.status_code != 200:
raise ValueError('Can not retrieve from {}'.format(url))
repo = json.loads(r.content)
if name != "-":
repo["name"] = name
commit_api = 'https://api.github.com/repos/{}/commits/{}'.format(url[19:], repo['default_branch'])
r = requests.get(commit_api, headers={'Authorization': 'token {}'.format(access_token)})
if r.status_code != 200:
raise ValueError('Can not retrieve from {}'.format(url))
commit = json.loads(r.content)
repo['last_commit_date'] = datetime.fromisoformat(commit['commit']['committer']['date'][:-1])
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 (r for r in repos if not(is_deprecated(r))):
f.write(repo_text(repo))
f.write(warning)
for repo in (r for r in repos if is_deprecated(r)):
f.write(repo_text(repo))
f.write(tail.format(datetime.now().strftime('%Y-%m-%dT%H:%M:%S%Z')))
def is_deprecated(repo):
return repo["html_url"] in deprecated_repos or (datetime.now() - repo['last_commit_date']).days > 365
def repo_text(repo):
repo_user_and_name = '/'.join(repo['html_url'].split('/')[-2:])
text = ""
text += f"- [{repo['name']}]({repo['html_url']}): {repo['description']} \n\n "
text += f"[![GitHub stars](https://img.shields.io/github/stars/{repo_user_and_name}.svg?style=social)]({repo['html_url']}) "
text += f"[![GitHub issues](https://img.shields.io/github/issues/{repo_user_and_name}.svg)]({repo['html_url']}/issues) "
text += f"[![GitHub last commit](https://img.shields.io/github/last-commit/{repo_user_and_name})]({repo['html_url']}/commits) "
text += "\n"
return text
if __name__ == '__main__':
main()