-
Notifications
You must be signed in to change notification settings - Fork 1
/
convert.py
48 lines (40 loc) · 1.4 KB
/
convert.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
from jinja2 import Template
import os
TEMPLATE = 'template.html'
MATRIX = 'matrix'
OUTPUT = 'web/index.html'
number = 1
def convert(file, num):
with open(file) as file:
lines = file.readlines()
data = {'category': {}}
category = ''
current_list = None
for line in lines:
if line.startswith('# '):
data['header'] = line.strip('#').strip()
data['number'] = '0' + str(num)
elif line.startswith('## '):
category = line.strip('##').strip()
data['category'][category] = []
current_list = data['category'][category]
elif line.startswith('- '):
current_list.append({'text': line.strip('-').strip(), 'subitems': []})
elif line.startswith(' - '):
if current_list:
current_list[-1]['subitems'].append(line.strip(' - ').strip())
else:
data['description'] = line.strip()
return data
if __name__ == '__main__':
data = []
files = os.listdir(MATRIX)
files.sort()
for file in files:
if file.endswith('.md'):
data.append(convert(os.path.join(MATRIX, file), number))
number += 1
template = Template(open(TEMPLATE).read())
levels = ((1, 'Trainee'), (2, 'Junior'), (3, 'Middle'), (4, 'Senior'), (5, 'Expert'))
with open(OUTPUT, 'w') as file:
file.write(template.render(data=data, levels=levels))