Skip to content

Commit 6bb5e61

Browse files
authored
fix(brasil): use geocodes instead of region (#35)
1 parent 64d3ad9 commit 6bb5e61

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

alertflow/dags/satellite-weather/brasil.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"""
1717

1818
import os
19+
from pathlib import Path
1920
from datetime import date, timedelta
2021
from itertools import chain
2122

@@ -35,8 +36,8 @@
3536
# 'email': [email_main],
3637
"email_on_failure": True,
3738
"email_on_retry": False,
38-
"retries": 2,
39-
"retry_delay": timedelta(minutes=2),
39+
"retries": 5,
40+
"retry_delay": timedelta(seconds=30),
4041
}
4142

4243

@@ -47,7 +48,6 @@
4748
schedule="@monthly",
4849
default_args=DEFAULT_ARGS,
4950
start_date=pendulum.datetime(2000, 1, 1),
50-
end_date=pendulum.datetime(2024, 1, 1),
5151
catchup=True,
5252
max_active_runs=14,
5353
) as dag:
@@ -75,14 +75,20 @@ def fetch_ds(locale, dt, uri, api_key):
7575
print("TABLE_GEO ", f"[{len(table_geocodes)}]: ", table_geocodes)
7676
print("DIFF_GEO: ", f"[{len(geocodes)}]: ", geocodes)
7777

78+
basename = str(dt).replace("-", "_") + locale
7879
with request.reanalysis_era5_land(
79-
str(dt).replace("-", "_") + locale,
80+
basename,
8081
api_token=api_key,
8182
date=str(dt),
8283
locale=locale,
8384
) as ds:
84-
for adm in ADM2.filter(adm0=locale):
85+
for geocode in geocodes:
86+
adm = ADM2.get(code=geocode):
8587
with engine.connect() as conn:
8688
ds.cope.to_sql(adm, conn, tablename, "weather")
89+
file = Path(f"{basename}.zip")
90+
if file.exists():
91+
file.unlink()
92+
print(f"{file} removed")
8793

8894
fetch_ds("BRA", DATE, URI["PSQL_MAIN_URI"], KEY["CDSAPI_KEY"])

0 commit comments

Comments
 (0)