From e2e7b7ec1f33e520cf09435a4dbc1d6f33fbfd12 Mon Sep 17 00:00:00 2001 From: Raissa Ferreira Date: Sat, 23 Feb 2019 12:21:02 -0300 Subject: [PATCH] feature: Include sortter script for mulheres.json file --- sorter.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 sorter.py diff --git a/sorter.py b/sorter.py new file mode 100644 index 0000000..ef4da38 --- /dev/null +++ b/sorter.py @@ -0,0 +1,25 @@ +import logging +from argparse import ArgumentParser, FileType +import json + +logger = logging.getLogger('sorter') +logging.basicConfig(level='INFO') + +parser = ArgumentParser( + description='This is a sorter script for mulheres.json file', +) + +parser.add_argument('-i', metavar='in-file', + type=FileType('rt', encoding='utf8')) + +parser.add_argument('-o', metavar='out-file', + type=FileType('w+b')) + +try: + results = parser.parse_args() + mulheres = json.loads(results.i.read()) + mulheres["mulheres"].sort(key=lambda item: item["name"]) + results.o.write(json.dumps(mulheres, indent=4, ensure_ascii=False).encode('utf8')) + logger.info("File generated successfully") +except Exception as e: + logger.exception(e) \ No newline at end of file