Skip to content

Commit

Permalink
feat(scot): rename dgaln to sudocuh
Browse files Browse the repository at this point in the history
  • Loading branch information
alexisig committed Oct 16, 2024
1 parent 1e5431e commit 4e0241f
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 10 deletions.
17 changes: 12 additions & 5 deletions airflow/dags/ingest_scots.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import requests
from airflow.decorators import dag, task
from include.container import Container
from include.pools import DBT_POOL
from pendulum import datetime

SCOT_ENDPOINT = "https://api-sudocuh.datahub.din.developpement-durable.gouv.fr/sudocuh/enquetes/ref/scot/liste/CSV?annee_cog=2024" # noqa: E501 (line too long)
Expand All @@ -17,7 +18,7 @@
doc_md=__doc__,
max_active_runs=1,
default_args={"owner": "Alexis Athlani", "retries": 3},
tags=["DGALN"],
tags=["SUDOCUH"],
)
def ingest_scots():
bucket_name = "airflow-staging"
Expand Down Expand Up @@ -56,7 +57,7 @@ def download_scot_communes() -> str:
def ingest_scots(path_on_bucket) -> int | None:
Container().s3().get_file(path_on_bucket, tmp_localpath_scot)
df = pd.read_csv(tmp_localpath_scot, sep=";")
table_name = "dgaln_scot"
table_name = "sudocuh_scot"
row_count = df.to_sql(table_name, con=Container().sqlalchemy_dbt_conn(), if_exists="replace")
os.remove(tmp_localpath_scot)
return row_count
Expand All @@ -65,16 +66,22 @@ def ingest_scots(path_on_bucket) -> int | None:
def ingest_scot_communes(path_on_bucket) -> int | None:
Container().s3().get_file(path_on_bucket, tmp_localpath_scot_communes)
df = pd.read_csv(tmp_localpath_scot_communes, sep=";")
table_name = "dgaln_scot_communes"
table_name = "sudocuh_scot_communes"
row_count = df.to_sql(table_name, con=Container().sqlalchemy_dbt_conn(), if_exists="replace")
os.remove(tmp_localpath_scot_communes)
return row_count

@task.bash(retries=0, trigger_rule="all_success", pool=DBT_POOL)
def dbt_build(**context):
return 'cd "${AIRFLOW_HOME}/include/sql/sparte" && dbt build -s sudocuh'

scots_path = download_scots()
scot_communes_path = download_scot_communes()

ingest_scots(scots_path)
ingest_scot_communes(scot_communes_path)
ingest_scots_result = ingest_scots(scots_path)
ingest_scot_communes_result = ingest_scot_communes(scot_communes_path)

ingest_scots_result >> ingest_scot_communes_result >> dbt_build()


ingest_scots()
2 changes: 1 addition & 1 deletion airflow/include/sql/sparte/dbt_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ models:
majic:
+schema: majic
dgaln:
+schema: dgaln
+schema: sudocuh
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ models:
sources:
- name: public
tables:
- name: dgaln_scot
- name: dgaln_scot_communes
- name: sudocuh_scot
- name: sudocuh_scot_communes
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ SELECT
perimetre_en_cours_pcpopulationtotale,
perimetre_en_cours_pcsuperficie

FROM {{ source('public', 'dgaln_scot') }}
FROM {{ source('public', 'sudocuh_scot') }}
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ SELECT
scot_en_cours_nom_schema,
scot_en_cours_noserie_procedure,
scot_en_cours_date_prescription
FROM {{ source('public', 'dgaln_scot_communes') }}
FROM {{ source('public', 'sudocuh_scot_communes') }}

0 comments on commit 4e0241f

Please sign in to comment.