From 53f265026c32b869211581d4ad47e8fde58a0330 Mon Sep 17 00:00:00 2001 From: Alexis Durgnat <alexis.durgnat@hesge.ch> Date: Fri, 1 Jul 2022 08:50:15 +0200 Subject: [PATCH] Prettify output JSON Merge context managers better directory check --- server.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/server.py b/server.py index c20995d..a9dd795 100644 --- a/server.py +++ b/server.py @@ -26,17 +26,17 @@ async def post_map(the_map: MapData): def write_map(map_data: MapData): dir_name = os.getenv("ESRI_OUTPUT_DIRECTORY", default=OUTPUT_DIR) - if not os.path.exists(dir_name): + if not os.path.exists(dir_name) or not os.path.isdir(dir_name): os.makedirs(dir_name, exist_ok=True) map_filename = path_join(dir_name, MAP_NAME) tag_filename = path_join(dir_name, TAG_LIST_NAME) - with open(map_filename, 'w') as map_file: + with open(map_filename, 'w') as map_file, \ + open(tag_filename, 'w') as tag_file: map_file.write(map_data.esri) - with open(tag_filename, 'w') as tag_file: jdic = { "tags": map_data.arucos } - json.dump(jdic, tag_file) + json.dump(jdic, tag_file, indent=4) return True -- GitLab