-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathupdate-known-implementations.py
More file actions
executable file
·72 lines (56 loc) · 2.14 KB
/
update-known-implementations.py
File metadata and controls
executable file
·72 lines (56 loc) · 2.14 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
#!/usr/bin/python3
import os
import json
import requests
import argparse
def simplify_message(message):
return message
def get_github_repos(username, page):
response = requests.get("https://api.github.com/users/" + username + "/repos?page=" + str(page))
parsed = json.loads(response.content.decode('utf-8'))
return parsed
def get_stuff_to_look_for() -> list:
"""
Look in the current directory for any subfolder.
In this repository those represent the projects that can be implemented.
"""
result = list()
for f in os.listdir("."):
if not os.path.isfile(f):
if not f.startswith("."):
result.append(f)
return result
def get_all_repositories(username: str) -> list:
page = 1
result = list()
repositories = [""]
while len(repositories) > 0:
repositories = get_github_repos(username, page)
for repository in repositories:
result.append(repository["name"])
page += 1
result.sort()
return result
def get_matching_repositories(repositories : list, repositoryPrefix : str) -> list:
result = list()
for repository in repositories:
if (repository.startswith(repositoryPrefix)):
result.append(repository)
return result
def write_known_implementations_readme(filename : str, repositories : list) -> None:
with open(filename, 'w') as f:
f.write('# Known Implementations\n')
f.write('\n')
for repository in repositories:
f.write("- [" + repository + "](https://github.com/stho32/" + repository + ")\n")
def update_known_implementations() -> None:
print(" - retrieving repositories")
repositories = get_all_repositories("stho32")
print(" - retrieving projects")
projects_to_look_for = get_stuff_to_look_for()
for project in projects_to_look_for:
print(" - updating " + project + " ...")
matching_repositories = get_matching_repositories(repositories, project + "-")
write_known_implementations_readme(project + "/KnownImplementations.md", matching_repositories)
if __name__ == "__main__":
update_known_implementations()