Skip to content
Snippets Groups Projects
Commit 53f26502 authored by Alexis Durgnat's avatar Alexis Durgnat :milky_way:
Browse files

Prettify output JSON

Merge context managers
better directory check
parent c41733d0
No related branches found
No related tags found
No related merge requests found
...@@ -26,17 +26,17 @@ async def post_map(the_map: MapData): ...@@ -26,17 +26,17 @@ async def post_map(the_map: MapData):
def write_map(map_data: MapData): def write_map(map_data: MapData):
dir_name = os.getenv("ESRI_OUTPUT_DIRECTORY", default=OUTPUT_DIR) 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) os.makedirs(dir_name, exist_ok=True)
map_filename = path_join(dir_name, MAP_NAME) map_filename = path_join(dir_name, MAP_NAME)
tag_filename = path_join(dir_name, TAG_LIST_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) map_file.write(map_data.esri)
with open(tag_filename, 'w') as tag_file:
jdic = { jdic = {
"tags": map_data.arucos "tags": map_data.arucos
} }
json.dump(jdic, tag_file) json.dump(jdic, tag_file, indent=4)
return True return True
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment