-
Notifications
You must be signed in to change notification settings - Fork 16
/
generate-table.py
56 lines (40 loc) · 1.6 KB
/
generate-table.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
import csv
import re
import os
excluded_files = ["sep_002_template", "README"]
base_dir = '.'
data = []
for file_name in os.listdir(base_dir):
base_name = os.path.splitext(file_name)[0]
extension = os.path.splitext(file_name)[1]
if extension != ".md" or base_name in excluded_files:
continue
with open(os.path.join(base_dir, file_name), 'r') as myfile:
values = {}
for line in myfile.readlines():
if "|" in line:
parts = [part.strip() for part in line.strip().split("|") if part]
if len(parts) == 1:
value = ""
else:
value = parts[1].strip().replace('<leave empty>', '')
key = parts[0].replace('*', '').strip()
if key.replace('-', ''): # ignore line under header row
values[key] = value
# Extract URLs from markdown links
p = re.compile(r'\[.+?\]\((.+?)\)')
m = p.match(values.get('Issue', ''))
if m:
values['Issue'] = m.group(1)
if not values:
print(f"No data for {file_name}")
values["SEP"] = base_name.lower().replace('sep_', '')
data.append(values)
data.sort(key=lambda x: x['SEP'])
fieldnames = ["SEP", "Type", "SBOL Version", "Status", "Issue", "Title", "Replaces", "Created", "Last modified",
"Editor", "Authors"]
with open('summary.csv', 'w') as csvfile:
writer = csv.DictWriter(csvfile, fieldnames=fieldnames, extrasaction='ignore')
writer.writeheader()
writer.writerows(data)
print(f"Processed {len(data)} files")