-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathparse_entries.py
45 lines (34 loc) · 1.27 KB
/
parse_entries.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
from __future__ import print_function
import os
import glob
import json
import yaml
CATEGORIES = ['web_services', 'codes', 'data', 'facilities']
TITLE = {}
TITLE['facilities'] = "Observatories and Facilities"
TITLE['web_services'] = "Online/Web Services"
TITLE['codes'] = "Codes and Software"
TITLE['data'] = "Datasets"
database = []
for category in CATEGORIES:
category_database = {}
category_database['short'] = category
category_database['title'] = TITLE[category]
category_database['entries'] = []
for entry in glob.glob(os.path.join('entries', category, '*.yaml')):
print("Parsing {0}...".format(entry))
with open(entry) as infile:
content = yaml.safe_load(infile)
short = os.path.splitext(os.path.basename(entry))[0]
entryObj = {}
for key in content:
if content[key] is not None:
entryObj[key] = content[key]
else:
if key == 'text':
raise ValueError("text field should not be empty: {0}".format(entry))
category_database['entries'].append(entryObj)
database.append(category_database)
with open('database.json', 'w') as outfile:
json.dump(database, outfile, sort_keys=True, indent=4,
separators=(',', ': '))