From 7acb43134096d313b6cb87adda96a6cd6e0fcde9 Mon Sep 17 00:00:00 2001 From: Emilio Mariscal Date: Mon, 18 Nov 2024 11:39:20 -0300 Subject: [PATCH] Upload HTML file to S3. Fix code. Add a few comments. Ignore system MacOS files --- .gitignore | 2 ++ API/api_worker.py | 19 ++++++++++++++++--- requirements.txt | 2 +- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index c74b2f26..143eb173 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,5 @@ Pipfile.lock #backend backend/data backend/.env + +.DS_Store diff --git a/API/api_worker.py b/API/api_worker.py index a7085178..9a1262cc 100644 --- a/API/api_worker.py +++ b/API/api_worker.py @@ -219,9 +219,10 @@ def process_raw_data(self, params, user=None): file_parts, ) + # Post-proccessing: Generate GeoJSON/HTML stats and transliterations polygon_stats = None geojson_stats_html = None - + download_html_url = None if "include_stats" or "include_translit" in params.dict(): post_processor = PostProcessor({ "include_stats": params.include_stats, @@ -245,9 +246,9 @@ def process_raw_data(self, params, user=None): tpl = "stats" if 'waterway' in post_processor.geoJSONStats.config.keys: tpl = "stats_waterway" - if 'highway' in post_processor.geoJSONStats.config.keys: + elif 'highway' in post_processor.geoJSONStats.config.keys: tpl = "stats_highway" - if 'building' in post_processor.geoJSONStats.config.keys: + elif 'building' in post_processor.geoJSONStats.config.keys: tpl = "stats_building" project_root = pathlib.Path(__file__).resolve().parent tpl_path = os.path.join(project_root, "../src/post_processing/{tpl}_tpl.html".format(tpl=tpl)) @@ -322,6 +323,15 @@ def process_raw_data(self, params, user=None): upload_name, file_suffix="zip" if bind_zip else params.output_type.lower(), ) + + # If there's an HTML file, upload it too + if geojson_stats_html: + download_html_url = file_transfer_obj.upload( + upload_html_path, + upload_name, + file_suffix="html", + ) + else: # give the static file download url back to user served from fastapi static export path download_url = str(upload_file_path) @@ -347,6 +357,9 @@ def process_raw_data(self, params, user=None): } if polygon_stats: final_response["stats"] = polygon_stats + if download_html_url: + final_response["download_html_url"] = download_html_url + return final_response except Exception as ex: diff --git a/requirements.txt b/requirements.txt index 9e7b5a68..1364e704 100644 --- a/requirements.txt +++ b/requirements.txt @@ -56,7 +56,7 @@ psutil==5.9.8 tqdm==4.66.2 # stats for geojson data -geojson-stats==0.2.2 +geojson-stats==0.2.3 # transliterations transliterate==1.10.2