diff --git a/app/main.py b/app/main.py index 5a9d729..dfe0db0 100755 --- a/app/main.py +++ b/app/main.py @@ -43,9 +43,15 @@ async def get_test(): @app.get("/download/") -async def download_grib(background_tasks: BackgroundTasks): - """Download and process GRIB files into csv of requested parameters""" - background_tasks.add_task(service_grib.extract_useful_data) +async def download_grib( + background_tasks: BackgroundTasks, + target_time: str = None, +): + """Download and process GRIB files into csv of requested parameters + + :param target_time: well formed ISO 8601 time string, we will try to download GRIB available just before it + """ + background_tasks.add_task(service_grib.extract_useful_data, target_time) return JSONResponse(content={"status": "Background task started"}) diff --git a/services/grib/service.py b/services/grib/service.py index b6ddb20..08072f4 100644 --- a/services/grib/service.py +++ b/services/grib/service.py @@ -117,12 +117,17 @@ class Grib: ) @staticmethod - def extract_useful_data(): + def extract_useful_data(target_time: str = None): """Download and process GRIB files into csv of requested parameters + :param target_time: well formed ISO 8601 time string, we will try to download GRIB available just before it + :returns: filenames of the resulting csv """ - target_time = Grib.fresh_grib_time() + if not target_time: + target_time = Grib.fresh_grib_time() + else: + target_time = Grib.fresh_grib_time(datetime.fromisoformat(target_time)) save_to = f"{target_time.strftime('%Y%m%d')}-{str((target_time.hour // 6) * 6).zfill(2)}.csv" for forecast_hour in range(MAX_FORECAST_HOUR):