-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdump_convert.py
executable file
·41 lines (30 loc) · 1.22 KB
/
dump_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
#!/usr/bin/env python3
from brickset import read_jsonl, write_csv, header_dict
import os
# check for data directory
if not os.path.exists('data'):
raise RuntimeError('data directory missing!')
# check for data/themes.jsonl
themes_file = os.path.join('data', 'themes.jsonl')
if not os.path.exists(themes_file):
raise RuntimeError('themes.json missing!')
themes = read_jsonl(themes_file)
filename = os.path.join('data', 'themes.csv')
write_csv(filename, themes, header_dict(themes[0]))
themes_directories = [name for name in os.listdir('data') if os.path.isdir(os.path.join('data', name))]
global_sets = []
csv_types = []
# check each theme
for theme_directory in themes_directories:
for type in ['sets']: # 'subthemes', 'years'
# load
items_file = os.path.join('data', theme_directory, '{}_{}.jsonl'.format(theme_directory, type))
items = read_jsonl(items_file)
# write csv
if type in csv_types:
filename = os.path.join('data', theme_directory, '{}_{}.csv'.format(theme_directory, type))
write_csv(filename, items, header_dict(items[0]))
if type == 'sets':
global_sets.extend(items)
filename = os.path.join('data', 'sets.csv')
write_csv(filename, global_sets, header_dict(global_sets[0]))