-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathprof_extractor.py
57 lines (40 loc) · 1.19 KB
/
prof_extractor.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
import os
import json
import re
import pprint
output_data = {}
with open("Profiles.txt") as fd:
family = None
norm = None
unit = None
headers = None
while True:
line = fd.readline()
if line == "":
break
elif line.startswith('#'):
continue
elif line == "\n":
family = None
norm = None
unit = None
headers = None
elif line.startswith('*'):
family = line.strip('*\n')
norm = fd.readline().strip('*\n')
unit = fd.readline().strip('*\n')
headers = fd.readline().strip('*\n').split("/")
output_data[family] = {
"norm":norm,
"unit":unit,
"fillet":True,
"sizes":{}
}
current_data = output_data[family]
else:
data_line = re.split(r'\t+', line.strip("\n").rstrip('\t'))
data_line = [s.strip() for s in data_line]
d = dict(zip(headers[1:], data_line[1:]))
current_data['sizes'][data_line[0]] = d
with open("metal.json", "w") as fd:
json.dump(output_data, fd, indent=4)