From de80660e1a5dae3b34de5e4262f72ce575e5fe25 Mon Sep 17 00:00:00 2001 From: linogaliana Date: Thu, 19 Sep 2024 08:45:57 +0000 Subject: [PATCH] Ajoute une option filename --- cartiflette/api/output.py | 6 ++++++ cartiflette/utils/create_path_bucket.py | 8 ++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/cartiflette/api/output.py b/cartiflette/api/output.py index 2cca8a8..c17854e 100644 --- a/cartiflette/api/output.py +++ b/cartiflette/api/output.py @@ -29,7 +29,10 @@ def download_from_cartiflette_inner( provider: str = "IGN", dataset_family: str = "ADMINEXPRESS", source: str = "EXPRESS-COG-TERRITOIRE", + filename: str = "raw", return_as_json: bool = False, + *args, + **kwargs, ) -> typing.Union[gpd.GeoDataFrame, str]: """ Downloads and aggregates official geographic datasets using the Cartiflette API @@ -97,6 +100,7 @@ def download_from_cartiflette_inner( year=year, crs=crs, simplification=simplification, + filename=filename, ) gdf_list.append(gdf_single) @@ -123,6 +127,7 @@ def download_cartiflette_single( value: typing.Union[str, int, float] = "28", crs: typing.Union[list, str, int, float] = 2154, simplification: typing.Union[str, int, float] = None, + filename: str = "raw", *args, **kwargs, ): @@ -148,6 +153,7 @@ def download_cartiflette_single( "dataset_family": dataset_family, "source": source, "simplification": simplification, + "filename": filename } ) diff --git a/cartiflette/utils/create_path_bucket.py b/cartiflette/utils/create_path_bucket.py index f21f666..9ae6e32 100644 --- a/cartiflette/utils/create_path_bucket.py +++ b/cartiflette/utils/create_path_bucket.py @@ -20,6 +20,7 @@ class ConfigDict(TypedDict): year: str crs: Optional[int] value: str + filename: Optional[str] def create_path_bucket(config: ConfigDict) -> str: @@ -55,13 +56,16 @@ def create_path_bucket(config: ConfigDict) -> str: value = config.get("value") crs = config.get("crs", 2154) simplification = config.get("simplification", 0) + filename = config.get("filename") if simplification is None: simplification = 0 simplification = int(simplification) - filename = config.get("filename") + # Un hack pour modifier la valeur si jamais le pattern du filename n'est pas raw.{vectorfile_format} + if filename == "value": + filename = value write_path = ( f"{bucket}/{path_within_bucket}" @@ -78,7 +82,7 @@ def create_path_bucket(config: ConfigDict) -> str: ).replace("'", "") if filename: - write_path += f"/{filename}" + write_path += f"/{filename}.{vectorfile_format}" elif vectorfile_format == "shp": write_path += "/" else: