From c41733d075ec50f4d687cf91796cca1d3d28adc0 Mon Sep 17 00:00:00 2001 From: Alexis Durgnat <alexis.durgnat@hesge.ch> Date: Thu, 30 Jun 2022 10:14:37 +0200 Subject: [PATCH] Fix tag filename and api retval --- server.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/server.py b/server.py index 3a1476e..c20995d 100644 --- a/server.py +++ b/server.py @@ -12,6 +12,7 @@ TAG_LIST_NAME = "tags.json" app = FastAPI() + class MapData(BaseModel): esri: str arucos: List[Dict] @@ -19,14 +20,16 @@ class MapData(BaseModel): @app.post("/map") async def post_map(the_map: MapData): - write_map(the_map) - return "ok" + result = write_map(the_map) + return {"success": result} def write_map(map_data: MapData): dir_name = os.getenv("ESRI_OUTPUT_DIRECTORY", default=OUTPUT_DIR) + if not os.path.exists(dir_name): + os.makedirs(dir_name, exist_ok=True) map_filename = path_join(dir_name, MAP_NAME) - tag_filename = path_join(dir_name, MAP_NAME) + tag_filename = path_join(dir_name, TAG_LIST_NAME) with open(map_filename, 'w') as map_file: map_file.write(map_data.esri) with open(tag_filename, 'w') as tag_file: @@ -34,6 +37,7 @@ def write_map(map_data: MapData): "tags": map_data.arucos } json.dump(jdic, tag_file) + return True def path_join(p, f): -- GitLab