Commit 9a96b3f8 authored by Vilem Ded's avatar Vilem Ded
Browse files

feat: script exporting xlsx to json

help message:
export_xls_to_json.py [-h] [-f FILE [FILE ...]] [-d DIRNAME] [-o OUTPUT_DIR]
parent 49dafe90
import argparse
import os
import pathlib
from metadata_tools.importxls.dish_xls_exporter import DishXlsExporter
from metadata_tools.importxls.export_utils import save_exported_datasets_to_file
parser = argparse.ArgumentParser(description='Load XLS file and export as JSON')
parser.add_argument(
'-f',
'--file',
nargs='+',
help='Path to XLS/XLSX file to parse',
default=False)
parser.add_argument(
'-d',
'--directory',
help='Directory with XLS/XLSX files',
default=False,
dest='dirname')
parser.add_argument(
'-o',
'--output-dir',
help='Path to the directory to store JSON files to',
default=".",
dest="output_dir"
)
args = parser.parse_args()
fileList = []
if args.dirname:
dirname = args.dirname
for f in os.listdir(dirname):
if os.path.isfile(f):
fileList += os.path.join(dirname, f)
if args.file:
fileList += args.file
exporter = DishXlsExporter()
for fname in fileList:
dataset_dict = exporter.export_submission(fname)
fname_json = pathlib.Path(fname).stem + ".json"
fname_out = os.path.join(args.output_dir, fname_json)
with open(fname_out, 'w') as outfile:
save_exported_datasets_to_file(dataset_dict, outfile)
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