-
Notifications
You must be signed in to change notification settings - Fork 0
/
collectyaml.py
executable file
·50 lines (43 loc) · 1.03 KB
/
collectyaml.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
#!/usr/bin/env python3
import csv
import re
import yaml
from collections import OrderedDict
from pathlib import Path
basic_rules = {}
with open('src/improvgrammar/basic.csv') as f:
rows = list(csv.reader(f))
columns = []
for (i, header) in enumerate(rows[0]):
basic_rules[header] = {
'groups': [{
'tags': [],
'phrases': [row[i] for row in rows[1:] if row[i]],
}],
}
with open('src/improvgrammar/basic.yaml', 'w') as f:
yaml.dump(basic_rules, f, indent=2)
paths = []
# datas = []
root = Path('src/improvgrammar')
for p in root.glob('*.yaml'):
if p.stem == 'basic':
continue
paths.append(p)
paths.append(root / 'basic.yaml')
print(paths)
with open('src/improvgrammar/all.js', 'w') as f:
text = """
{requires}
export default Object.assign({{}}, {assignments})
""".strip().format(
requires='\n'.join([
"import {stem} from './{stem}.yaml';".format(stem=p.stem)
for p in paths
]),
assignments=', '.join([
p.stem for p in paths
]),
)
print(text)
f.write(text)