Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MEP - 8.2.0 #696

Merged
merged 147 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
147 commits
Select commit Hold shift + click to select a range
07c2918
fix(admin): replace GeoModelAdmin by GISModelAdmin
alexisig Sep 30, 2024
1f316c4
feat(majic): add ingest_majic dag to airflow
alexisig Oct 2, 2024
3ab6770
feat(ingest_majic): code cleanup
alexisig Oct 2, 2024
c96bdba
chore(cerema): remove unused files
alexisig Oct 2, 2024
f52081c
feat(epci): load epcis with airflow
alexisig Oct 3, 2024
b88c633
Merge pull request #588 from MTES-MCT/fix-deprecated-geo-model-admin
alexisig Oct 3, 2024
4f513c7
Merge pull request #595 from MTES-MCT/feat-majic-airflow
alexisig Oct 3, 2024
2070334
Merge pull request #601 from MTES-MCT/feat-admin-express-epci
alexisig Oct 9, 2024
28d7fb4
test(signup): add password validation
alexisig Oct 9, 2024
cff6c9f
feat(signup): add password validation
alexisig Oct 9, 2024
486e44a
fix(crips): simplify notifications
alexisig Oct 10, 2024
169774f
fix(signals): remove typing from on_notification_save
alexisig Oct 10, 2024
da51749
feat(crisp): simplify notification
alexisig Oct 10, 2024
3a2c286
feat(signals): simplify format_message
alexisig Oct 10, 2024
799c388
Merge pull request #631 from MTES-MCT/fix-crisp-notifications
alexisig Oct 10, 2024
a3466b6
Merge pull request #610 from MTES-MCT/feat-password-validation
alexisig Oct 10, 2024
56f772d
feat(ocsge): add source for 2a"
alexisig Oct 13, 2024
dff59fd
Merge pull request #635 from MTES-MCT/feat-ocsge-2a
alexisig Oct 13, 2024
1fd8d99
fix(dbt): fix incremental delete perf issue
alexisig Oct 13, 2024
91c0f86
Htmx middleware
smdsgn Aug 2, 2024
15487d1
Dashboard layout
smdsgn Aug 2, 2024
9f9b4c0
Refactoring WIP
smdsgn Aug 2, 2024
0d3aa4c
Remove test view
smdsgn Aug 3, 2024
8f8554d
Remove old templates
smdsgn Aug 3, 2024
13fab9d
Remove test view url
smdsgn Aug 3, 2024
dc785a9
Add diagnostic title component
smdsgn Aug 4, 2024
9d9c27e
Refactoring crud templates
smdsgn Aug 4, 2024
767d8eb
Create static map component
smdsgn Aug 4, 2024
7c46428
Remove standalone static map views and url
smdsgn Aug 7, 2024
5a2fff7
Refactoring directories
smdsgn Aug 7, 2024
45c5ac6
Replace htmx with react router
smdsgn Aug 12, 2024
edc0cae
Fix missing package
smdsgn Aug 12, 2024
c1c8d00
Config react alias
smdsgn Aug 12, 2024
48822d8
Fix react version warning
smdsgn Aug 12, 2024
b663db3
Prepare templates for migration to React
smdsgn Aug 12, 2024
d42dde1
Migrate overview component to React
smdsgn Aug 13, 2024
3325bd0
Get project detail api
smdsgn Aug 13, 2024
73e76a1
Remove old unused code
smdsgn Aug 23, 2024
1bc4dca
Custom tag highcharts data
smdsgn Aug 23, 2024
39cd17a
Make charts working and improvements
smdsgn Aug 23, 2024
932368b
Fix charts buttons
smdsgn Aug 23, 2024
0bbca50
Enabling HMR
smdsgn Aug 26, 2024
6059c18
Add scalingo node buildpack
smdsgn Aug 26, 2024
70c8d03
Improve react template logic
smdsgn Aug 30, 2024
816260c
React boundary error
smdsgn Aug 30, 2024
f93c8a9
Improve react htmx hook
smdsgn Aug 30, 2024
c83ea96
Date format utils
smdsgn Aug 30, 2024
eaf0768
React guide component
smdsgn Aug 30, 2024
0fe1648
React page title component
smdsgn Aug 30, 2024
34b8360
React diag download component
smdsgn Aug 30, 2024
0911870
React drawer component
smdsgn Aug 30, 2024
8a407dd
React drawer component
smdsgn Aug 30, 2024
a98cfc6
React Footer component WIP
smdsgn Aug 30, 2024
087db30
React Navbar component
smdsgn Aug 30, 2024
caba8cd
React header component
smdsgn Aug 30, 2024
b637d0f
React top bar component
smdsgn Aug 30, 2024
ae1d28e
Add new components to dashboard
smdsgn Aug 30, 2024
f2a164f
Cleaning
smdsgn Aug 30, 2024
0a76c91
Update Guide component style
smdsgn Sep 2, 2024
d14023e
React search bar component
smdsgn Sep 2, 2024
f6bf0e7
Display ocsge status message
smdsgn Sep 4, 2024
cb58a4d
React footer
smdsgn Sep 5, 2024
633ce77
Comparison lands forms
smdsgn Sep 11, 2024
7b7e108
Improve ui
smdsgn Sep 11, 2024
03708b2
Cleaning
smdsgn Sep 11, 2024
d08f6f3
Improve typescript and linting
smdsgn Sep 12, 2024
ae1c5fe
Cleaning
smdsgn Sep 12, 2024
e9c2ce5
Cleaning
smdsgn Sep 12, 2024
49d7f4d
Fix babel config
smdsgn Sep 12, 2024
ff8bbfe
Fix index padding
smdsgn Sep 13, 2024
2a56178
Remove unused scripts
smdsgn Sep 13, 2024
0af99cd
Update ui
smdsgn Sep 13, 2024
50a3cb0
remove node_modules from slugignore
smdsgn Sep 16, 2024
db80054
Change buildpacks order
smdsgn Sep 16, 2024
cec3115
Fix display home ocsge map
smdsgn Sep 16, 2024
d9ae7ef
Prevent source map in prod
smdsgn Sep 16, 2024
7c346bc
Distinct cache for fragment and full template
smdsgn Sep 17, 2024
78ef053
Improve is_commune flag in report
smdsgn Sep 17, 2024
bdc1f5e
Make Matomo work with react
smdsgn Sep 18, 2024
35aa5aa
Display message if there is no gpu data
smdsgn Sep 20, 2024
91e94c1
Fix dashboard content width
smdsgn Sep 27, 2024
8da3ad2
Replace old search with react search
smdsgn Sep 19, 2024
9543403
Use trigram similarity score
smdsgn Sep 19, 2024
4c939ad
Display search results in one list with tags
smdsgn Sep 20, 2024
fb16f71
Hide old territories from search
smdsgn Sep 20, 2024
2f335ac
Fix is Fetching
smdsgn Sep 20, 2024
0b30d16
Add missing create url
smdsgn Sep 20, 2024
790eb40
Fix gtag undefined if not activated
smdsgn Sep 20, 2024
967a95d
Update assets/scripts/components/layout/Header.tsx
smdsgn Sep 30, 2024
75c1cfe
Make skip character more explicit
smdsgn Sep 30, 2024
2b578a5
Fix search to ignore accents and case in trigram similarity
smdsgn Sep 30, 2024
3535fe2
lint
smdsgn Oct 2, 2024
75f0a27
Add comments for better understanding
smdsgn Oct 2, 2024
cac1c53
Replace hardcoded urls
smdsgn Oct 3, 2024
26bf09b
Fix htmx forms
smdsgn Oct 3, 2024
9a61024
Simplify OCSGE/GPU status check and improve conditional rendering logic
smdsgn Oct 4, 2024
6ebe852
Fix ui
smdsgn Oct 4, 2024
d3a95fc
Refactoring download buttons and local report ui
smdsgn Oct 11, 2024
cb5f8e0
Switch to custom export server instead of Highcharts export server
smdsgn Oct 11, 2024
f209aea
Improve error boundary ui
smdsgn Oct 11, 2024
525bd6e
Merge pull request #636 from MTES-MCT/fix-delete-from
alexisig Oct 14, 2024
2d505fc
Add highcharts to csp connect-src
smdsgn Oct 14, 2024
4aaee5e
Prevent sonarcloud warning integrity bundle dev
smdsgn Oct 14, 2024
03b2c99
feat(update_app): allow dag to use subset on territory
alexisig Oct 14, 2024
e0db9af
feat(cog): add dagg to ingest cog mouvement
alexisig Oct 14, 2024
e9c8deb
doc(ingest_cog_change): remove doc
alexisig Oct 14, 2024
fec768b
Merge pull request #642 from MTES-MCT/feat-airflow-insee-cog
alexisig Oct 14, 2024
9092ce6
Merge pull request #641 from MTES-MCT/feat-airflow-more-subset
alexisig Oct 14, 2024
7578f28
Standardization of graphics colors
smdsgn Oct 14, 2024
c4b791d
Remove bundle dev nonce
smdsgn Oct 14, 2024
5b2480b
fix(project): fix get_neighbors by buffering the compbined_emprise
alexisig Oct 16, 2024
22b0fc5
Merge pull request #649 from MTES-MCT/fix-compairson-lands
alexisig Oct 16, 2024
1e5431e
feat(scot): add dag and dbt models
alexisig Oct 16, 2024
4e0241f
feat(scot): rename dgaln to sudocuh
alexisig Oct 16, 2024
a28a833
Merge pull request #650 from MTES-MCT/feat-scot
alexisig Oct 16, 2024
bc31ffb
Include land type label in administration models
smdsgn Oct 16, 2024
ed01143
Fix add comparison land form ui
smdsgn Oct 16, 2024
a29f580
Replace land type with land type label in react search component
smdsgn Oct 16, 2024
114f1f8
feat(conso-cog): adapt conso to cog 2024
alexisig Oct 16, 2024
a6f9a8f
fix(signin): remove typos
alexisig Oct 17, 2024
641ace2
Merge pull request #653 from MTES-MCT/fix-coquilles
alexisig Oct 17, 2024
fb50338
Add missing images
smdsgn Oct 17, 2024
78f63aa
Fix exclude current land from neighbors
smdsgn Oct 17, 2024
4b08588
Fix highlight current scot in charts
smdsgn Oct 17, 2024
c941d0c
Fix modal set target 2031
smdsgn Oct 17, 2024
3f195d1
Merge pull request #648 from MTES-MCT/feat-airflow-insee-cog
alexisig Oct 17, 2024
b764e41
Add missing htmx import
smdsgn Oct 24, 2024
6a61b37
Fix htmx syntax error
smdsgn Oct 24, 2024
3a0dea4
Remove extra padding on maplibre template
smdsgn Oct 24, 2024
27c6af7
Remove unused files
smdsgn Oct 24, 2024
a56482e
Merge pull request #668 from MTES-MCT/fix/maplibre-htmx-and-template
alexisig Oct 24, 2024
a113ab4
feat(ocsge): add 85 46 76 27 73
alexisig Oct 27, 2024
5ec4d3c
Merge pull request #682 from MTES-MCT/feat-ocsge-octobre-2024
alexisig Oct 27, 2024
e13ea46
fix(difference_commune): incremental loading condition
alexisig Oct 27, 2024
1419767
Merge pull request #683 from MTES-MCT/fix-difference-commune-perf
alexisig Oct 27, 2024
fa70356
Fix dashboard faq links url
smdsgn Oct 18, 2024
0186c4f
Update crisp faq url
smdsgn Oct 28, 2024
7e7b1cb
Fix prevent missing theme map file
smdsgn Oct 28, 2024
6e6c54d
Add htmx nonce config
smdsgn Oct 28, 2024
3c3b98f
Add missing google csp rules
smdsgn Oct 28, 2024
7d836f5
Update call to action background color
smdsgn Oct 28, 2024
80fa99d
Remove fr-container class from notice component
smdsgn Oct 28, 2024
b35ee20
Fix typo
smdsgn Oct 28, 2024
34cb5dc
Fix typo
smdsgn Oct 28, 2024
53a7ac5
Merge pull request #694 from MTES-MCT/fix/typo
alexisig Oct 28, 2024
8d4ff2b
feat(version): bump to 8.2.0
alexisig Oct 29, 2024
56440d5
Merge pull request #695 from MTES-MCT/feat-version.8.2.°
alexisig Oct 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 0 additions & 19 deletions .babelrc

This file was deleted.

1 change: 1 addition & 0 deletions .buildpacks
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
https://github.com/Scalingo/apt-buildpack
https://github.com/Scalingo/nodejs-buildpack
https://github.com/Scalingo/python-buildpack
3 changes: 1 addition & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ EMAIL_SMTP_KEY=ASK_A_MAINTAINER
EMAIL_HOST_USER=YOUR_EMAIL

MATOMO_ACTIVATE=0
MATOMO_SCRIPT_NAME=container_mlVvm9TG.js
MATOMO_TOKEN=TO_FILL

HIGHCHART_SERVER=https://highcharts-export.osc-fr1.scalingo.io

MATTERMOST_WEBHOOK=https://mattermost.incubateur.net/hooks/uak581f8bidyxp5td67rurj5sh
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,7 @@ staticroot/*
public_data/static/SSCH*
diff_bfc_*
.idea

# Webpack bundles
static/assets/scripts/
static/assets/styles/*.css.map
2 changes: 2 additions & 0 deletions .slugignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
assets/scripts
assets/styles
assets/types
/node_modules
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ Le site est désormais accessible en local à cette adresse:
| LOCAL_FILE_DIRECTORY | Emplacement des données locales (utile pour charger des shapefile en local au lieu de S3) | public_data/local_data |
| MATTERMOST_WEBHOOK | Webhook personnel pour envoyer des messages dans Mattermost | https://mattermost.incubateur.net/hooks/uak581f8bidyxp5td67rurj5sh |
| MATOMO_ACTIVATE | Détermine si des infos doivent être envoyé à Matomo | 0 |
| MATOMO_SCRIPT_NAME | | |
| MATOMO_TOKEN | Token pour envoyer les données à Matomo | |
| POSTGRES_DB | Nom de la base de donnée (local uniquement) | postgres |
| POSTGRES_USER | Username par défaut de la base de donnée (local uniquement) | postgres |
| POSTGRES_PASSWORD | Password par défaut de la base de donnée (local uniquement) | postgres |
Expand Down
36 changes: 18 additions & 18 deletions airflow/dags/ingest_admin_express.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,51 +39,46 @@ def get_source_by_name(name: str) -> dict:
type="string",
enum=zones,
),
"refresh_source": Param(
default=False,
description="Rafraîchir la source",
type="boolean",
),
},
)
def ingest_admin_express():
bucket_name = "airflow-staging"
tmp_path = "/tmp/admin_express"

@task.python
def download_admin_express(**context) -> str:
print(context["params"]["zone"])
url = get_source_by_name(context["params"]["zone"])["url"]

print(url)
filename = url.split("/")[-1]
print(filename)
path_on_bucket = f"{bucket_name}/{filename}"
print(path_on_bucket)

file_exists = Container().s3().exists(path_on_bucket)

if file_exists and not context["params"]["refresh_source"]:
return path_on_bucket

opener = URLopener()
opener.addheader("User-Agent", "Mozilla/5.0")
opener.retrieve(url=url, filename=filename)

Container().s3().put_file(filename, path_on_bucket)

os.remove(filename)
return path_on_bucket

@task.python
def ingest(path_on_bucket, **context) -> str:
srid = get_source_by_name(context["params"]["zone"])["srid"]
shp_to_table_map = get_source_by_name(context["params"]["zone"])["shapefile_to_table"]
source = get_source_by_name(context["params"]["zone"])
srid = source["srid"]
print(srid)
shp_to_table_map = source["shapefile_to_table"]
print(shp_to_table_map)

with Container().s3().open(path_on_bucket, "rb") as f:
py7zr.SevenZipFile(f, mode="r").extractall()
for dirpath, _, filenames in os.walk("."):
py7zr.SevenZipFile(f, mode="r").extractall(path=tmp_path)
for dirpath, _, filenames in os.walk(tmp_path):
for filename in filenames:
if filename.endswith(".shp"):
table_name = shp_to_table_map.get(filename)
if not table_name:
continue
path = os.path.abspath(os.path.join(dirpath, filename))
print(path)
cmd = [
"ogr2ogr",
"-f",
Expand Down Expand Up @@ -113,9 +108,14 @@ def dbt_run(**context):
dbt_run_cmd = f"dbt build -s {dbt_selector}"
return 'cd "${AIRFLOW_HOME}/include/sql/sparte" && ' + dbt_run_cmd

@task.bash
def cleanup() -> str:
return f"rm -rf {tmp_path}"

path_on_bucket = download_admin_express()
ingest_result = ingest(path_on_bucket)
ingest_result >> dbt_run()
ingest_result >> cleanup()


# Instantiate the DAG
Expand Down
61 changes: 61 additions & 0 deletions airflow/dags/ingest_cog_changes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import os
from urllib.request import URLopener

import pandas as pd
from airflow.decorators import dag, task
from airflow.models.param import Param
from include.container import Container
from pendulum import datetime

urls = {
"2024": "https://www.insee.fr/fr/statistiques/fichier/7766585/v_mvt_commune_2024.csv",
}


@dag(
start_date=datetime(2024, 1, 1),
schedule="@once",
catchup=False,
doc_md=__doc__,
max_active_runs=1,
default_args={"owner": "Alexis Athlani", "retries": 3},
tags=["INSEE"],
params={
"year": Param(
default="2024",
description="Année des changements",
type="string",
enum=list(urls.keys()),
),
},
)
def ingest_cog_changes():
bucket_name = "airflow-staging"
tmp_localpath = "/tmp/cog_changes"

@task.python
def download_change_file(**context) -> str:
year = context["params"]["year"]
filename = urls[year].split("/")[-1]
path_on_bucket = f"{bucket_name}/{filename}"
opener = URLopener()
opener.addheader("User-Agent", "Mozilla/5.0")
opener.retrieve(url=urls[year], filename=filename)
Container().s3().put_file(filename, path_on_bucket)
os.remove(filename)
return path_on_bucket

@task.python
def ingest(path_on_bucket, **context) -> int | None:
Container().s3().get_file(path_on_bucket, tmp_localpath)
df = pd.read_csv(tmp_localpath)
table_name = f"insee_cog_changes_{context['params']['year']}"
row_count = df.to_sql(table_name, con=Container().sqlalchemy_dbt_conn(), if_exists="replace")
os.remove(tmp_localpath)
return row_count

path_on_bucket = download_change_file()
ingest(path_on_bucket)


ingest_cog_changes()
101 changes: 101 additions & 0 deletions airflow/dags/ingest_majic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import shutil
import subprocess
from typing import List
from zipfile import ZipFile

from airflow.decorators import dag, task
from airflow.operators.python import PythonOperator
from include.container import Container
from include.majic.sources import sources
from include.pools import DBT_POOL
from include.utils import (
get_dbt_command_from_directory,
get_first_shapefile_path_in_dir,
)
from pendulum import datetime

BUCKET_NAME = "airflow-staging"
TMP_PATH = "/tmp/majic"


def load_shapefile_to_postgres(source: dict):
shapefile_on_s3 = source["shapefile_on_s3"]
srid = source["srid"]
table_name = source["table_name"]
path_on_bucket = f"{BUCKET_NAME}/{shapefile_on_s3}"

with Container().s3().open(path_on_bucket, "rb") as f:
zip_file = ZipFile(f)
tmp_path = f"{TMP_PATH}/{table_name}"
zip_file.extractall(tmp_path)
shapefile_path = get_first_shapefile_path_in_dir(tmp_path)
cmd = [
"ogr2ogr",
"-f",
'"PostgreSQL"',
f'"{Container().gdal_dbt_conn().encode()}"',
"-overwrite",
"-lco",
"GEOMETRY_NAME=geom",
"-a_srs",
f"EPSG:{srid}",
"-nlt",
"MULTIPOLYGON",
"-nlt",
"PROMOTE_TO_MULTI",
"-nln",
table_name,
shapefile_path,
"--config",
"PG_USE_COPY",
"YES",
]
subprocess.run(" ".join(cmd), shell=True, check=True)

shutil.rmtree(TMP_PATH)


@dag(
start_date=datetime(2024, 1, 1),
schedule="@once",
catchup=False,
max_active_runs=1,
default_args={"owner": "Alexis Athlani", "retries": 3},
tags=["Majic", "Cerema"],
)
def ingest_majic():
# Les fichiers de consommation d'espace sont sur le dropbox du Cerema
# Ils ne sont pas acessibles programmatiquement, donc il faut les télécharger manuellement
# et les mettre dans le bucket airflow-staging, dans le dossier majic

ingest_tasks: List[PythonOperator] = []

for source in sources:
ingest_task = PythonOperator(
task_id=f"ingest_{source['table_name']}",
python_callable=load_shapefile_to_postgres,
op_kwargs={"source": source},
)
ingest_tasks.append(ingest_task)

@task.bash(pool=DBT_POOL)
def dbt_build() -> str:
return get_dbt_command_from_directory(cmd="dbt build -s +consommation.sql+")

@task.bash()
def cleanup() -> str:
return f"rm -rf {TMP_PATH}"

for i in range(len(ingest_tasks) - 1):
ingest_tasks[i] >> ingest_tasks[i + 1]

build = dbt_build()
cleanup_task = cleanup()

# Build the models and clean up the temporary files
# after all the ingest tasks have completed
ingest_tasks[-1].set_downstream(build)
build.set_downstream(cleanup_task)


ingest_majic()
87 changes: 87 additions & 0 deletions airflow/dags/ingest_scots.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import os

import pandas as pd
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)
SCOT_COMMUNES_ENDPOINT = "https://api-sudocuh.datahub.din.developpement-durable.gouv.fr/sudocuh/enquetes/ref/scot/communes/CSV?annee_cog=2024" # noqa: E501 (line too long)


@dag(
start_date=datetime(2024, 1, 1),
schedule="@once",
catchup=False,
doc_md=__doc__,
max_active_runs=1,
default_args={"owner": "Alexis Athlani", "retries": 3},
tags=["SUDOCUH"],
)
def ingest_scots():
bucket_name = "airflow-staging"
scot_filename = "scot.csv"
scot_communes_filename = "scot_communes.csv"
tmp_localpath_scot = f"/tmp/{scot_filename}"
tmp_localpath_scot_communes = f"/tmp/{scot_communes_filename}"

@task.python
def download_scots() -> str:
request = requests.get(SCOT_ENDPOINT)

with open(tmp_localpath_scot, "wb") as f:
f.write(request.content)

path_on_bucket = f"{bucket_name}/{scot_filename}"

Container().s3().put_file(tmp_localpath_scot, path_on_bucket)
os.remove(tmp_localpath_scot)
return path_on_bucket

@task.python
def download_scot_communes() -> str:
request = requests.get(SCOT_COMMUNES_ENDPOINT)

with open(tmp_localpath_scot_communes, "wb") as f:
f.write(request.content)

path_on_bucket = f"{bucket_name}/{scot_communes_filename}"

Container().s3().put_file(tmp_localpath_scot_communes, path_on_bucket)
os.remove(tmp_localpath_scot_communes)
return path_on_bucket

@task.python
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 = "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

@task.python
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 = "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_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()
Loading