forked from yoyowallet/tech-radar
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgenerate.py
99 lines (79 loc) · 3.32 KB
/
generate.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import csv
import json
import re
import datetime
import requests
# Publicly available
RINGS_CSV = 'https://docs.google.com/spreadsheets/u/1/d/1JKkdaeGJPrLhgtZ2jAPBjS8cpaJGL6PgK0SU28fgIJw/export?format=csv&id=1JKkdaeGJPrLhgtZ2jAPBjS8cpaJGL6PgK0SU28fgIJw&gid=0'
QUADRANTS_CSV = 'https://docs.google.com/spreadsheets/u/1/d/1YDRKVUGHRVREZ1gGUwRGffb7sQpVV3ztR4KTRSqwHds/export?format=csv&id=1YDRKVUGHRVREZ1gGUwRGffb7sQpVV3ztR4KTRSqwHds&gid=0'
ENTRIES_CSV = 'https://docs.google.com/spreadsheets/u/1/d/1Op2gILhJWK1YldR60xWBYMKxajSkHsy25DL_7y14HpU/export?format=csv&id=1Op2gILhJWK1YldR60xWBYMKxajSkHsy25DL_7y14HpU&gid=0'
def iter_csv(url):
response = requests.get(url, stream=True)
response.raise_for_status()
return csv.DictReader(response.iter_lines(decode_unicode=True))
TARGET_HTML = 'docs/index.html'
MARKER_START = '/* RADAR START */'
MARKER_END = '/* RADAR END */'
def main():
# Quadrants
quadrants = []
quadrant_to_index = {}
for row in iter_csv(QUADRANTS_CSV):
quadrants.append({'name': row['Name']})
quadrant_to_index[row['Name']] = len(quadrants) - 1
# Rings
rings = []
ring_to_index = {}
for row in iter_csv(RINGS_CSV):
rings.append({'name': row['Name'].upper(), 'color': row['Colour']})
ring_to_index[row['Name']] = len(rings) - 1
# Entries
entries = []
for row in iter_csv(ENTRIES_CSV):
# we will not import technologies with "Remove". These are old ones which we have removed from the chart
if row['Ring'] == 'Remove':
continue
if not row['Link']:
confluence_link = 'No Confluence page available. please check out: <a target="_blank" style="font-size:12pt" ' \
'href="https://productsup.atlassian.net/wiki/spaces/EN/pages/1930429957/Overview' \
'+Technologies">Tech Radar Technologies</a>'
else:
confluence_link = 'Learn more about: <a target="_blank" style="font-size:12pt" href="' + str(row['Link']) + '">' + str(row['Name']) + '</a> in our Documentation.'
entries.append({
'quadrant': quadrant_to_index[row['Quadrant']],
'ring': ring_to_index[row['Ring']],
'label': row['Name'],
'explanation': confluence_link,
'moved': row['Move']
})
dt = datetime.datetime.today()
radar_config = {
'svg_id': 'radar',
'width': 1450,
'height': 1000,
'colors': {
'background': "#fff",
'grid': "#bbb",
'inactive': "#ddd"
},
'title': "Productsup Tech Radar — as of " + str(dt.strftime("%Y.%m")),
'print_layout': True,
'quadrants': quadrants,
'rings': rings,
'entries': entries,
}
with open("JsonPrettyPrint.json", "w") as write_file:
json.dump(radar_config, write_file, indent=4, separators=(", ", ": "), sort_keys=True)
with open("JsonPrettyPrint.json", 'r') as f:
radar_json_string = f.read()
with open(TARGET_HTML, 'r') as f:
html = f.read()
html = re.sub(
f'({re.escape(MARKER_START)}).*({re.escape(MARKER_END)})',
r'\1' + radar_json_string.replace('\\', r'\\') + r'\2',
html, flags=re.S
)
with open(TARGET_HTML, 'w') as f:
f.write(html)
if __name__ == '__main__':
main()