...
 
Commits (2)
......@@ -465,6 +465,25 @@ def generate_dataset_data(target_dir, ds_code, structure_info, datacube_filepath
return True
def rebuild_category_tree(target_dir):
"""Read datasets dataset.json files, extract datasets (code, name) and rebuild category tree"""
log.info("Read dataset info from dataset.json files...")
dataset_info_list = []
for ds_dir in (f for f in target_dir.glob('*') if f.is_dir()):
ds_json_file = ds_dir / 'dataset.json'
if ds_json_file.exists():
with ds_json_file.open('rt', encoding='utf-8') as fd:
ds_content = json.load(fd)
dataset_info_list.append((ds_content['code'], {'name': ds_content['name']}))
# Write category tree
log.info('Rewrite category_tree.json')
category_json_content = build_category_json(dict(dataset_info_list))
cu.write_json_file(target_dir / 'category_tree.json',
category_json_content)
def main():
""" Converts downloaded source data into json data """
parser = argparse.ArgumentParser(description=__doc__,
......@@ -481,6 +500,8 @@ def main():
help='level of logging messages')
parser.add_argument('--only-dataset', default=False,
help='restrict convert to this dataset')
parser.add_argument('--rebuild-category-tree', action='store_true',
help='only rebuild category_tree.json from json-data')
args = parser.parse_args()
......@@ -501,6 +522,10 @@ def main():
if not target_dir.exists():
parser.error("Target dir {!r} not found".format(str(target_dir)))
# Only rebuild category_tree.json from json_data
if args.rebuild_category_tree:
return rebuild_category_tree(target_dir)
# Standard metadata
cu.write_json_file(target_dir / 'provider.json', PROVIDER_JSON)
......
......@@ -13,7 +13,7 @@ from lxml import etree
# Chosen themes
CATEGORY_LABELS = {
'42': ' Manufacturing, mining and quarrying',
'42': 'Manufacturing, mining and quarrying',
'45': 'Trade, accommodation and food services, tourism',
'51': 'Foreign trade',
'61': 'Prices',
......@@ -26,9 +26,13 @@ CATEGORY_LABELS = {
SUB_CATEGORIES = {
'42': [
('421', 'Short-term surveys'),
('422', 'Structural surveys'),
('423', 'Specialised stat. of individual economic branches'),
],
'45': [
('452', 'Short-term stat.: trade, accomm. and food services'),
('453', 'Structural stat.: trade, accomm. and food services'),
('454', 'Specialised statistics of trade, accomm., tourism'),
],
'51': [],
'61': [
......