add: optional download time param

dev
g 4 years ago
parent 55aa465c78
commit 8af53de5ad

@ -43,9 +43,15 @@ async def get_test():
@app.get("/download/") @app.get("/download/")
async def download_grib(background_tasks: BackgroundTasks): async def download_grib(
"""Download and process GRIB files into csv of requested parameters""" background_tasks: BackgroundTasks,
background_tasks.add_task(service_grib.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
"""
background_tasks.add_task(service_grib.extract_useful_data, target_time)
return JSONResponse(content={"status": "Background task started"}) return JSONResponse(content={"status": "Background task started"})

@ -117,12 +117,17 @@ class Grib:
) )
@staticmethod @staticmethod
def extract_useful_data(): def extract_useful_data(target_time: str = None):
"""Download and process GRIB files into csv of requested parameters """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 :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" 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): for forecast_hour in range(MAX_FORECAST_HOUR):

Loading…
Cancel
Save