-
Notifications
You must be signed in to change notification settings - Fork 39
/
generate-csv.py
executable file
·46 lines (33 loc) · 1.1 KB
/
generate-csv.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
#!/usr/bin/env python
""" Quick and Dirty Roberto Martelloni's script to generate a CSV """
import re
import os
def area_from_filename(filename):
filename_parts = filename.split("-")
area_id = filename_parts[1]
name = filename_parts[2].split(".")
name = name[0].replace("_", " ")
return [area_id, name]
def parse_md(filename):
in_table = False
for line in open(filename):
if re.match(r"\s*\|", line):
if re.match(r"\s*\|\s*#\s*\|", line):
in_table = True
continue
if re.match(r"\|\s*:?--+:?\s*\|", line):
continue
if in_table:
start = area_from_filename(filename)
line = line.replace("*", "")
line = line.replace('"', '""')
line = re.split(r"\s*\|\s*", line)
print('"' + '","'.join(start + line[1:-1]) + '"')
else:
in_table = False
def main():
for file in sorted(os.listdir("./en")):
if file.find("-V") != -1:
parse_md("./en/" + file)
if __name__ == '__main__':
main()