Import résultats législatives

This commit is contained in:
2024-06-20 14:45:53 +02:00
parent 8f8028028e
commit 7aa92d28d4
5 changed files with 695 additions and 33 deletions

View File

@ -11,7 +11,7 @@ from nupes.models.europeennes2024 import *
def importer_resultats_bv(engine: Engine, verbose: bool = False) -> None:
file = get_file("https://www.data.gouv.fr/fr/datasets/r/cc1883d9-1265-4365-b754-fb6aef22d82e",
"resultats-europeennes-par-bureau-de-vote.csv")
"resultats-europeennes-2024-par-bureau-de-vote.csv")
with file.open('r') as f:
reader = DictReader(f, delimiter=';')
@ -20,7 +20,8 @@ def importer_resultats_bv(engine: Engine, verbose: bool = False) -> None:
com_code = str(row['Code commune']).zfill(5)
bv_code = row['Code BV']
if com_code.startswith("987"): # Les communes de Polynésie française ne sont pas importées
if com_code.startswith("987") or com_code.startswith("988"):
# Les communes de Polynésie française ne sont pas importées
continue
if com_code == "60694":
@ -111,7 +112,7 @@ def importer_resultats_bv(engine: Engine, verbose: bool = False) -> None:
def importer_resultats_commune(engine: Engine, verbose: bool = False) -> None:
file = get_file("https://www.data.gouv.fr/fr/datasets/r/6a782ef9-8ad6-4e66-832d-338b1041a42d",
"resultats-europeennes-par-commune.csv")
"resultats-europeennes-2024-par-commune.csv")
with file.open('r') as f:
reader = DictReader(f, delimiter=';')
@ -123,7 +124,8 @@ def importer_resultats_commune(engine: Engine, verbose: bool = False) -> None:
if dpt_code == "ZX": # Saint-Martin/Saint-Barthélémy
dpt_code = "977"
if dpt_code == "987": # Les communes de Polynésie française ne sont pas importées
if dpt_code == "977" or dpt_code == "987" or dpt_code == "988":
# Les communes de Polynésie française ne sont pas importées
continue
if com_code == "60694":
@ -195,7 +197,7 @@ def importer_resultats_commune(engine: Engine, verbose: bool = False) -> None:
def importer_resultats_circo(engine: Engine, verbose: bool = False) -> None:
file = get_file("https://www.data.gouv.fr/fr/datasets/r/ee37cbef-3d2a-4efe-a395-530b85a63028",
"resultats-europeennes-par-circonscription.csv")
"resultats-europeennes-2024-par-circonscription.csv")
with file.open('r') as f:
reader = DictReader(f, delimiter=';')
@ -268,7 +270,7 @@ def importer_resultats_circo(engine: Engine, verbose: bool = False) -> None:
def importer_resultats_departement(engine: Engine, verbose: bool = False) -> None:
file = get_file("https://www.data.gouv.fr/fr/datasets/r/b77cc4da-644f-4323-b6f7-ae6fe9b33f86",
"resultats-europeennes-par-departement.csv")
"resultats-europeennes-2024-par-departement.csv")
with file.open('r') as f:
reader = DictReader(f, delimiter=';')
@ -330,7 +332,7 @@ def importer_resultats_departement(engine: Engine, verbose: bool = False) -> Non
def importer_resultats_region(engine: Engine, verbose: bool = False) -> None:
file = get_file("https://www.data.gouv.fr/fr/datasets/r/7c3a854b-7344-4c68-b1f9-9d651b4ca823",
"resultats-europeennes-par-region.csv")
"resultats-europeennes-2024-par-region.csv")
with file.open('r') as f:
reader = DictReader(f, delimiter=';')