forked from SiegeEngineers/aoc-dev-resources
-
Notifications
You must be signed in to change notification settings - Fork 0
/
to_markdown.py
50 lines (37 loc) · 1.53 KB
/
to_markdown.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
"""Write markdown for the README."""
import yaml
from collections import defaultdict
DATA_PATH = 'data.yaml'
TITLE = 'AoC developer resources'
DESCRIPTION = 'Useful repositories and articles related to developing software and analysis for Age of Empires II.'
def append(text, line):
"""Append a line to the text."""
return f"{text}{line}\n"
def write_markdown(data):
"""Write markdown based on data file."""
text = ''
text = append(text, f"# {TITLE}")
text = append(text, DESCRIPTION)
categories = defaultdict(list)
for repo in data['repositories']:
categories[repo['category']].append(repo)
text = append(text, "## Repositories")
for cat, repos in categories.items():
text = append(text, f'### {cat}')
text = append(text, "| Repository | Language | Maturity | Version |")
text = append(text, "| --- | --- | --- | --- |")
for repo in repos:
text = append(text, '| [{}]({}) | {} | {} | {} |'.format(
repo['name'], repo['url'], repo['language'], repo['maturity'], repo['version'])
)
text = append(text, "## APIs & Protocols")
for api in data['apis']:
text = append(text, f"- [{api['name']}]({api['url']})")
text = append(text, "## Articles")
for article in data['articles']:
text = append(text, f"- [{article['name']}]({article['url']})")
return text
if __name__ == '__main__':
"""Script entry point."""
with open(DATA_PATH) as handle:
print(write_markdown(yaml.safe_load(handle)))