Commit 6c15f6f3 authored by Bruno Duyé's avatar Bruno Duyé

Add flat categories_tree

parent cd9cec89
......@@ -40,6 +40,7 @@ import logging
import os
import sys
import toolz
from babel import numbers
from docopt import docopt
from slugify import slugify
......@@ -85,6 +86,7 @@ def main():
appendix_dirnames = sorted([dirname for dirname in os.listdir(source_dir)
if os.path.isdir(os.path.join(source_dir, dirname)) and not dirname.startswith('.')
]) # List source_dir subdirs
category_tree = []
for appendix_code in appendix_dirnames:
log.info("* Appendix: {!r}".format(appendix_code))
# Iterate through datasets
......@@ -96,13 +98,22 @@ def main():
with open(os.path.join(appendix_path, "datasets.json")) as datasets_json_file:
datasets_information = json.load(datasets_json_file)
for dataset_dict in datasets_information:
treat_dataset(dataset_dict, appendix_path)
dataset_code, dataset_name = treat_dataset(dataset_dict, appendix_path)
# Add dataset information to category_tree
category_tree.append(toolz.valfilter(lambda e: e, { # filter not provided names
"code": dataset_code,
"name": dataset_name
}))
# Write categories_tree.json file
write_json_file(os.path.join(target_dir, 'categories_tree.json'), category_tree)
log.info('\nEND')
def treat_dataset(dataset_dict, appendix_path):
"""Create dataset dir, series files and dataset.json file
Return dataset_code, dataset_name
"""
dataset_code = dataset_dict["dataset_code"]
log.debug('- Dataset {!r}'.format(dataset_code))
......@@ -159,6 +170,7 @@ def treat_dataset(dataset_dict, appendix_path):
# 'dimensions_values_labels': dimensions_values_labels, # TODO: manually add frequencies labels
})
return dataset_code, dataset_name
def write_json_file(file_path, data):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment