Compare commits
No commits in common. "2908f94b4a16146f5b6594fe7bc2873b97f787cb" and "47cfdf705ac5dfbb4a4c8e637c038ed253c5a888" have entirely different histories.
2908f94b4a
...
47cfdf705a
8
main.py
8
main.py
@ -14,12 +14,9 @@ def parse_args():
|
|||||||
parser = argparse.ArgumentParser(description="Gestion d'élections")
|
parser = argparse.ArgumentParser(description="Gestion d'élections")
|
||||||
parser.add_argument('--type', '-t', type=str, help="Type d'élection",
|
parser.add_argument('--type', '-t', type=str, help="Type d'élection",
|
||||||
choices=["présidentielle", "législatives", "sénatoriales", "européennes",
|
choices=["présidentielle", "législatives", "sénatoriales", "européennes",
|
||||||
"régionales", "départementales", "municipales"], default="législatives")
|
"régionales", "départementales", "municipales"], default="européennes")
|
||||||
parser.add_argument('--year', '-y', type=int, help="Année de l'élection",
|
parser.add_argument('--year', '-y', type=int, help="Année de l'élection",
|
||||||
choices=[2022, 2024], default=2024)
|
choices=[2022, 2024], default=2024)
|
||||||
parser.add_argument('--round', '-r', type=int,
|
|
||||||
help="Tour de l'élection à importer (0 pour tous, valeur par défaut)",
|
|
||||||
choices=[0, 1, 2], default=0)
|
|
||||||
parser.add_argument('action', help="Action à réaliser",
|
parser.add_argument('action', help="Action à réaliser",
|
||||||
choices=["import_candidats", "import_geographie", "import_resultats",
|
choices=["import_candidats", "import_geographie", "import_resultats",
|
||||||
"import_resultats_web", "export_resultats"])
|
"import_resultats_web", "export_resultats"])
|
||||||
@ -33,7 +30,6 @@ def main():
|
|||||||
load_dotenv()
|
load_dotenv()
|
||||||
|
|
||||||
args = parse_args()
|
args = parse_args()
|
||||||
data_round = args.round
|
|
||||||
debug = args.debug
|
debug = args.debug
|
||||||
verbose = args.verbose
|
verbose = args.verbose
|
||||||
|
|
||||||
@ -62,7 +58,7 @@ def main():
|
|||||||
case "import_resultats":
|
case "import_resultats":
|
||||||
if verbose:
|
if verbose:
|
||||||
print(f"Import des résultats pour les élections {args.type} {args.year}")
|
print(f"Import des résultats pour les élections {args.type} {args.year}")
|
||||||
election_module.import_resultats.run(engine, data_round, verbose)
|
election_module.import_resultats.run(engine, verbose)
|
||||||
case "import_resultats_web":
|
case "import_resultats_web":
|
||||||
if verbose:
|
if verbose:
|
||||||
print(f"Import des résultats depuis le web pour les élections {args.type} {args.year}")
|
print(f"Import des résultats depuis le web pour les élections {args.type} {args.year}")
|
||||||
|
@ -417,11 +417,7 @@ def calculer_resultats_france(engine: Engine, verbose: bool = False) -> None:
|
|||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
|
|
||||||
def run(engine: Engine, data_round: int = 0, verbose: bool = False) -> None:
|
def run(engine: Engine, verbose: bool = False) -> None:
|
||||||
if data_round != 0 and data_round != 1:
|
|
||||||
# Un seul tour à l'élection européenne
|
|
||||||
return
|
|
||||||
|
|
||||||
importer_resultats_region(engine, verbose)
|
importer_resultats_region(engine, verbose)
|
||||||
importer_resultats_departement(engine, verbose)
|
importer_resultats_departement(engine, verbose)
|
||||||
calculer_resultats_france(engine, verbose)
|
calculer_resultats_france(engine, verbose)
|
||||||
|
@ -9,7 +9,7 @@ from nupes.models import BureauVote
|
|||||||
from nupes.models.legislatives2022 import *
|
from nupes.models.legislatives2022 import *
|
||||||
|
|
||||||
|
|
||||||
def importer_resultats_bv(engine: Engine, data_round: int = 0, verbose: bool = False) -> None:
|
def importer_resultats_bv(engine: Engine, verbose: bool = False) -> None:
|
||||||
tours = [(1, "https://www.data.gouv.fr/fr/datasets/r/a1f73b85-8194-44f4-a2b7-c343edb47d32"),
|
tours = [(1, "https://www.data.gouv.fr/fr/datasets/r/a1f73b85-8194-44f4-a2b7-c343edb47d32"),
|
||||||
(2, "https://www.data.gouv.fr/fr/datasets/r/96ffddda-59b4-41b8-a6a3-dfe1adb7fa36")]
|
(2, "https://www.data.gouv.fr/fr/datasets/r/96ffddda-59b4-41b8-a6a3-dfe1adb7fa36")]
|
||||||
|
|
||||||
@ -20,10 +20,6 @@ def importer_resultats_bv(engine: Engine, data_round: int = 0, verbose: bool = F
|
|||||||
for bv in session.execute(select(BureauVote)).scalars().all()}
|
for bv in session.execute(select(BureauVote)).scalars().all()}
|
||||||
|
|
||||||
for tour, file_url in tours:
|
for tour, file_url in tours:
|
||||||
if data_round > 0 and tour != data_round:
|
|
||||||
# On saute ce tour
|
|
||||||
continue
|
|
||||||
|
|
||||||
file = get_file(file_url, f"resultats-legislatives-2022-t{tour}-par-bureau-de-vote.csv")
|
file = get_file(file_url, f"resultats-legislatives-2022-t{tour}-par-bureau-de-vote.csv")
|
||||||
|
|
||||||
with file.open('r', encoding="ISO-8859-1") as f:
|
with file.open('r', encoding="ISO-8859-1") as f:
|
||||||
@ -170,20 +166,18 @@ def importer_resultats_bv(engine: Engine, data_round: int = 0, verbose: bool = F
|
|||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
|
|
||||||
def importer_resultats_commune(engine: Engine, data_round: int = 0, verbose: bool = False) -> None:
|
def importer_resultats_commune(engine: Engine, verbose: bool = False) -> None:
|
||||||
tours = [(1, "https://www.data.gouv.fr/fr/datasets/r/a9a82bcc-304e-491f-a4f0-c06575113745"),
|
tours = [(1, "https://www.data.gouv.fr/fr/datasets/r/a9a82bcc-304e-491f-a4f0-c06575113745"),
|
||||||
(2, "https://www.data.gouv.fr/fr/datasets/r/e79b2e51-0841-4266-b626-57cb271c7a35")]
|
(2, "https://www.data.gouv.fr/fr/datasets/r/e79b2e51-0841-4266-b626-57cb271c7a35")]
|
||||||
|
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
for resultats_commune in session.execute(select(ResultatsCommuneLegislatives2022)).scalars().all():
|
for resultats_commune in session.execute(select(ResultatsCommuneLegislatives2022)).scalars().all():
|
||||||
if data_round == 0 or data_round == 1:
|
|
||||||
resultats_commune.inscrits_t1 = 0
|
resultats_commune.inscrits_t1 = 0
|
||||||
resultats_commune.votants_t1 = 0
|
resultats_commune.votants_t1 = 0
|
||||||
resultats_commune.abstentions_t1 = 0
|
resultats_commune.abstentions_t1 = 0
|
||||||
resultats_commune.exprimes_t1 = 0
|
resultats_commune.exprimes_t1 = 0
|
||||||
resultats_commune.blancs_t1 = 0
|
resultats_commune.blancs_t1 = 0
|
||||||
resultats_commune.nuls_t1 = 0
|
resultats_commune.nuls_t1 = 0
|
||||||
if data_round == 0 or data_round == 2:
|
|
||||||
resultats_commune.inscrits_t2 = 0
|
resultats_commune.inscrits_t2 = 0
|
||||||
resultats_commune.votants_t2 = 0
|
resultats_commune.votants_t2 = 0
|
||||||
resultats_commune.abstentions_t2 = 0
|
resultats_commune.abstentions_t2 = 0
|
||||||
@ -192,18 +186,12 @@ def importer_resultats_commune(engine: Engine, data_round: int = 0, verbose: boo
|
|||||||
resultats_commune.nuls_t2 = 0
|
resultats_commune.nuls_t2 = 0
|
||||||
|
|
||||||
for voix_nuance in resultats_commune.voix:
|
for voix_nuance in resultats_commune.voix:
|
||||||
if data_round == 0 or data_round == 1:
|
|
||||||
voix_nuance.voix_t1 = 0
|
voix_nuance.voix_t1 = 0
|
||||||
if data_round == 0 or data_round == 2:
|
|
||||||
voix_nuance.voix_t2 = 0
|
voix_nuance.voix_t2 = 0
|
||||||
|
|
||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
for tour, file_url in tours:
|
for tour, file_url in tours:
|
||||||
if data_round > 0 and tour != data_round:
|
|
||||||
# On saute ce tour
|
|
||||||
continue
|
|
||||||
|
|
||||||
file = get_file(file_url,
|
file = get_file(file_url,
|
||||||
f"resultats-legislatives-2022-t{tour}-par-commune.csv")
|
f"resultats-legislatives-2022-t{tour}-par-commune.csv")
|
||||||
|
|
||||||
@ -322,15 +310,11 @@ def importer_resultats_commune(engine: Engine, data_round: int = 0, verbose: boo
|
|||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
|
|
||||||
def importer_resultats_circo(engine: Engine, data_round: int = 0, verbose: bool = False) -> None:
|
def importer_resultats_circo(engine: Engine, verbose: bool = False) -> None:
|
||||||
tours = [(1, "https://www.data.gouv.fr/fr/datasets/r/114b13e8-7ff9-437f-9ec8-7a29258a80e3"),
|
tours = [(1, "https://www.data.gouv.fr/fr/datasets/r/114b13e8-7ff9-437f-9ec8-7a29258a80e3"),
|
||||||
(2, "https://www.data.gouv.fr/fr/datasets/r/436b9eaa-64e1-46bd-ad1d-9638ebbd6caf")]
|
(2, "https://www.data.gouv.fr/fr/datasets/r/436b9eaa-64e1-46bd-ad1d-9638ebbd6caf")]
|
||||||
|
|
||||||
for tour, file_url in tours:
|
for tour, file_url in tours:
|
||||||
if data_round > 0 and tour != data_round:
|
|
||||||
# On saute ce tour
|
|
||||||
continue
|
|
||||||
|
|
||||||
file = get_file(file_url, f"resultats-legislatives-2022-t{tour}-par-circonscription.csv")
|
file = get_file(file_url, f"resultats-legislatives-2022-t{tour}-par-circonscription.csv")
|
||||||
|
|
||||||
with file.open('r', encoding="ISO-8859-1") as f:
|
with file.open('r', encoding="ISO-8859-1") as f:
|
||||||
@ -444,15 +428,11 @@ def importer_resultats_circo(engine: Engine, data_round: int = 0, verbose: bool
|
|||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
|
|
||||||
def importer_resultats_departement(engine: Engine, data_round: int = 0, verbose: bool = False) -> None:
|
def importer_resultats_departement(engine: Engine, verbose: bool = False) -> None:
|
||||||
tours = [(1, "https://www.data.gouv.fr/fr/datasets/r/4acba699-e512-4dc5-87c7-ba74db773633"),
|
tours = [(1, "https://www.data.gouv.fr/fr/datasets/r/4acba699-e512-4dc5-87c7-ba74db773633"),
|
||||||
(2, "https://www.data.gouv.fr/fr/datasets/r/bc76bd72-cf65-45b2-b651-7716dc3c5520")]
|
(2, "https://www.data.gouv.fr/fr/datasets/r/bc76bd72-cf65-45b2-b651-7716dc3c5520")]
|
||||||
|
|
||||||
for tour, file_url in tours:
|
for tour, file_url in tours:
|
||||||
if data_round > 0 and tour != data_round:
|
|
||||||
# On saute ce tour
|
|
||||||
continue
|
|
||||||
|
|
||||||
file = get_file(file_url, f"resultats-legislatives-2022-t{tour}-par-departement.csv")
|
file = get_file(file_url, f"resultats-legislatives-2022-t{tour}-par-departement.csv")
|
||||||
|
|
||||||
with file.open('r', encoding="ISO-8859-1") as f:
|
with file.open('r', encoding="ISO-8859-1") as f:
|
||||||
@ -551,15 +531,11 @@ def importer_resultats_departement(engine: Engine, data_round: int = 0, verbose:
|
|||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
|
|
||||||
def importer_resultats_region(engine: Engine, data_round: int = 0, verbose: bool = False) -> None:
|
def importer_resultats_region(engine: Engine, verbose: bool = False) -> None:
|
||||||
tours = [(1, "https://www.data.gouv.fr/fr/datasets/r/f79576c9-9ddc-43f9-8d99-f0856550054e"),
|
tours = [(1, "https://www.data.gouv.fr/fr/datasets/r/f79576c9-9ddc-43f9-8d99-f0856550054e"),
|
||||||
(2, "https://www.data.gouv.fr/fr/datasets/r/fdba421a-d4e9-4f38-9753-982a7c065911")]
|
(2, "https://www.data.gouv.fr/fr/datasets/r/fdba421a-d4e9-4f38-9753-982a7c065911")]
|
||||||
|
|
||||||
for tour, file_url in tours:
|
for tour, file_url in tours:
|
||||||
if data_round > 0 and tour != data_round:
|
|
||||||
# On saute ce tour
|
|
||||||
continue
|
|
||||||
|
|
||||||
file = get_file(file_url, f"resultats-legislatives-2022-t{tour}-par-region.csv")
|
file = get_file(file_url, f"resultats-legislatives-2022-t{tour}-par-region.csv")
|
||||||
|
|
||||||
with file.open('r', encoding="ISO-8859-1") as f:
|
with file.open('r', encoding="ISO-8859-1") as f:
|
||||||
@ -624,15 +600,10 @@ def importer_resultats_region(engine: Engine, data_round: int = 0, verbose: bool
|
|||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
|
|
||||||
def importer_resultats_france(engine: Engine, data_round: int = 0, verbose: bool = False) -> None:
|
def importer_resultats_france(engine: Engine, verbose: bool = False) -> None:
|
||||||
tours = [(1, "https://www.data.gouv.fr/fr/datasets/r/cbe72f2c-2c56-4251-89cb-213de8bfbea0"),
|
tours = [(1, "https://www.data.gouv.fr/fr/datasets/r/cbe72f2c-2c56-4251-89cb-213de8bfbea0"),
|
||||||
(2, "https://www.data.gouv.fr/fr/datasets/r/6639bb39-13ec-49dd-ab4d-1f8227b86c01")]
|
(2, "https://www.data.gouv.fr/fr/datasets/r/6639bb39-13ec-49dd-ab4d-1f8227b86c01")]
|
||||||
|
|
||||||
for tour, file_url in tours:
|
for tour, file_url in tours:
|
||||||
if data_round > 0 and tour != data_round:
|
|
||||||
# On saute ce tour
|
|
||||||
continue
|
|
||||||
|
|
||||||
file = get_file(file_url, f"resultats-legislatives-2022-t{tour}-france-entiere.csv")
|
file = get_file(file_url, f"resultats-legislatives-2022-t{tour}-france-entiere.csv")
|
||||||
|
|
||||||
with file.open('r', encoding="ISO-8859-1") as f:
|
with file.open('r', encoding="ISO-8859-1") as f:
|
||||||
@ -687,10 +658,10 @@ def importer_resultats_france(engine: Engine, data_round: int = 0, verbose: bool
|
|||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
|
|
||||||
def run(engine: Engine, data_round: int = 0, verbose: bool = False) -> None:
|
def run(engine: Engine, verbose: bool = False) -> None:
|
||||||
importer_resultats_france(engine, data_round, verbose)
|
importer_resultats_france(engine, verbose)
|
||||||
importer_resultats_region(engine, data_round, verbose)
|
importer_resultats_region(engine, verbose)
|
||||||
importer_resultats_departement(engine, data_round, verbose)
|
importer_resultats_departement(engine, verbose)
|
||||||
importer_resultats_circo(engine, data_round, verbose)
|
importer_resultats_circo(engine, verbose)
|
||||||
importer_resultats_commune(engine, data_round, verbose)
|
importer_resultats_commune(engine, verbose)
|
||||||
importer_resultats_bv(engine, data_round, verbose)
|
importer_resultats_bv(engine, verbose)
|
||||||
|
@ -9,9 +9,8 @@ from nupes.models import BureauVote
|
|||||||
from nupes.models.legislatives2024 import *
|
from nupes.models.legislatives2024 import *
|
||||||
|
|
||||||
|
|
||||||
def importer_resultats_bv(engine: Engine, data_round: int = 0, verbose: bool = False) -> None:
|
def importer_resultats_bv(engine: Engine, verbose: bool = False) -> None:
|
||||||
tours = [(1, "https://www.data.gouv.fr/fr/datasets/r/6813fb28-7ec0-42ff-a528-2bc3d82d7dcd"),
|
tours = [(1, "https://www.data.gouv.fr/fr/datasets/r/6813fb28-7ec0-42ff-a528-2bc3d82d7dcd")]
|
||||||
(2, "https://www.data.gouv.fr/fr/datasets/r/ca974f04-cfd9-4da8-8554-4a868a09c6c2")]
|
|
||||||
|
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
candidats = {(candidat.circonscription_id, candidat.numero): candidat
|
candidats = {(candidat.circonscription_id, candidat.numero): candidat
|
||||||
@ -20,10 +19,6 @@ def importer_resultats_bv(engine: Engine, data_round: int = 0, verbose: bool = F
|
|||||||
for bv in session.execute(select(BureauVote)).scalars().all()}
|
for bv in session.execute(select(BureauVote)).scalars().all()}
|
||||||
|
|
||||||
for tour, file_url in tours:
|
for tour, file_url in tours:
|
||||||
if data_round > 0 and tour != data_round:
|
|
||||||
# On saute ce tour
|
|
||||||
continue
|
|
||||||
|
|
||||||
file = get_file(file_url, f"resultats-legislatives-2024-t{tour}-par-bureau-de-vote.csv")
|
file = get_file(file_url, f"resultats-legislatives-2024-t{tour}-par-bureau-de-vote.csv")
|
||||||
|
|
||||||
with file.open('r') as f:
|
with file.open('r') as f:
|
||||||
@ -154,20 +149,17 @@ def importer_resultats_bv(engine: Engine, data_round: int = 0, verbose: bool = F
|
|||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
|
|
||||||
def importer_resultats_commune(engine: Engine, data_round: int = 0, verbose: bool = False) -> None:
|
def importer_resultats_commune(engine: Engine, verbose: bool = False) -> None:
|
||||||
tours = [(1, "https://www.data.gouv.fr/fr/datasets/r/bd32fcd3-53df-47ac-bf1d-8d8003fe23a1"),
|
tours = [(1, "https://www.data.gouv.fr/fr/datasets/r/bd32fcd3-53df-47ac-bf1d-8d8003fe23a1")]
|
||||||
(2, "https://www.data.gouv.fr/fr/datasets/r/5a8088fd-8168-402a-9f40-c48daab88cd1")]
|
|
||||||
|
|
||||||
with Session(engine) as session:
|
with Session(engine) as session:
|
||||||
for resultats_commune in session.execute(select(ResultatsCommuneLegislatives2024)).scalars().all():
|
for resultats_commune in session.execute(select(ResultatsCommuneLegislatives2024)).scalars().all():
|
||||||
if data_round == 0 or data_round == 1:
|
|
||||||
resultats_commune.inscrits_t1 = 0
|
resultats_commune.inscrits_t1 = 0
|
||||||
resultats_commune.votants_t1 = 0
|
resultats_commune.votants_t1 = 0
|
||||||
resultats_commune.abstentions_t1 = 0
|
resultats_commune.abstentions_t1 = 0
|
||||||
resultats_commune.exprimes_t1 = 0
|
resultats_commune.exprimes_t1 = 0
|
||||||
resultats_commune.blancs_t1 = 0
|
resultats_commune.blancs_t1 = 0
|
||||||
resultats_commune.nuls_t1 = 0
|
resultats_commune.nuls_t1 = 0
|
||||||
if data_round == 0 or data_round == 2:
|
|
||||||
resultats_commune.inscrits_t2 = 0
|
resultats_commune.inscrits_t2 = 0
|
||||||
resultats_commune.votants_t2 = 0
|
resultats_commune.votants_t2 = 0
|
||||||
resultats_commune.abstentions_t2 = 0
|
resultats_commune.abstentions_t2 = 0
|
||||||
@ -176,9 +168,7 @@ def importer_resultats_commune(engine: Engine, data_round: int = 0, verbose: boo
|
|||||||
resultats_commune.nuls_t2 = 0
|
resultats_commune.nuls_t2 = 0
|
||||||
|
|
||||||
for voix_nuance in resultats_commune.voix:
|
for voix_nuance in resultats_commune.voix:
|
||||||
if data_round == 0 or data_round == 1:
|
|
||||||
voix_nuance.voix_t1 = 0
|
voix_nuance.voix_t1 = 0
|
||||||
if data_round == 0 or data_round == 2:
|
|
||||||
voix_nuance.voix_t2 = 0
|
voix_nuance.voix_t2 = 0
|
||||||
|
|
||||||
session.commit()
|
session.commit()
|
||||||
@ -186,10 +176,6 @@ def importer_resultats_commune(engine: Engine, data_round: int = 0, verbose: boo
|
|||||||
com_codes = {commune.code_insee for commune in session.execute(select(Commune)).scalars().all()}
|
com_codes = {commune.code_insee for commune in session.execute(select(Commune)).scalars().all()}
|
||||||
|
|
||||||
for tour, file_url in tours:
|
for tour, file_url in tours:
|
||||||
if data_round > 0 and tour != data_round:
|
|
||||||
# On saute ce tour
|
|
||||||
continue
|
|
||||||
|
|
||||||
file = get_file(file_url,
|
file = get_file(file_url,
|
||||||
f"resultats-legislatives-2024-t{tour}-par-commune.csv")
|
f"resultats-legislatives-2024-t{tour}-par-commune.csv")
|
||||||
|
|
||||||
@ -297,15 +283,10 @@ def importer_resultats_commune(engine: Engine, data_round: int = 0, verbose: boo
|
|||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
|
|
||||||
def importer_resultats_circo(engine: Engine, data_round: int = 0, verbose: bool = False) -> None:
|
def importer_resultats_circo(engine: Engine, verbose: bool = False) -> None:
|
||||||
tours = [(1, "https://www.data.gouv.fr/fr/datasets/r/5163f2e3-1362-4c35-89a0-1934bb74f2d9"),
|
tours = [(1, "https://www.data.gouv.fr/fr/datasets/r/5163f2e3-1362-4c35-89a0-1934bb74f2d9")]
|
||||||
(2, "https://www.data.gouv.fr/fr/datasets/r/41ed46cd-77c2-4ecc-b8eb-374aa953ca39")]
|
|
||||||
|
|
||||||
for tour, file_url in tours:
|
for tour, file_url in tours:
|
||||||
if data_round > 0 and tour != data_round:
|
|
||||||
# On saute ce tour
|
|
||||||
continue
|
|
||||||
|
|
||||||
file = get_file(file_url, f"resultats-legislatives-2024-t{tour}-par-circonscription.csv")
|
file = get_file(file_url, f"resultats-legislatives-2024-t{tour}-par-circonscription.csv")
|
||||||
|
|
||||||
with file.open('r') as f:
|
with file.open('r') as f:
|
||||||
@ -404,15 +385,10 @@ def importer_resultats_circo(engine: Engine, data_round: int = 0, verbose: bool
|
|||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
|
|
||||||
def importer_resultats_departement(engine: Engine, data_round: int = 0, verbose: bool = False) -> None:
|
def importer_resultats_departement(engine: Engine, verbose: bool = False) -> None:
|
||||||
tours = [(1, "https://www.data.gouv.fr/fr/datasets/r/78c708c5-5bc5-438d-8379-f432beae3f2b"),
|
tours = [(1, "https://www.data.gouv.fr/fr/datasets/r/78c708c5-5bc5-438d-8379-f432beae3f2b")]
|
||||||
(2, "https://www.data.gouv.fr/fr/datasets/r/8d4a6927-c96f-4cf5-b757-ea745eca26bd")]
|
|
||||||
|
|
||||||
for tour, file_url in tours:
|
for tour, file_url in tours:
|
||||||
if data_round > 0 and tour != data_round:
|
|
||||||
# On saute ce tour
|
|
||||||
continue
|
|
||||||
|
|
||||||
file = get_file(file_url, f"resultats-legislatives-2024-t{tour}-par-departement.csv")
|
file = get_file(file_url, f"resultats-legislatives-2024-t{tour}-par-departement.csv")
|
||||||
|
|
||||||
with file.open('r') as f:
|
with file.open('r') as f:
|
||||||
@ -496,15 +472,10 @@ def importer_resultats_departement(engine: Engine, data_round: int = 0, verbose:
|
|||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
|
|
||||||
def importer_resultats_region(engine: Engine, data_round: int = 0, verbose: bool = False) -> None:
|
def importer_resultats_region(engine: Engine, verbose: bool = False) -> None:
|
||||||
tours = [(1, "https://www.data.gouv.fr/fr/datasets/r/f69ffab7-fe37-494e-ad6d-a7cfc80ddc1f"),
|
tours = [(1, "https://www.data.gouv.fr/fr/datasets/r/f69ffab7-fe37-494e-ad6d-a7cfc80ddc1f")]
|
||||||
(2, "https://www.data.gouv.fr/fr/datasets/r/ac4e272a-3ce2-4f20-941e-fb0ded444a5d")]
|
|
||||||
|
|
||||||
for tour, file_url in tours:
|
for tour, file_url in tours:
|
||||||
if data_round > 0 and tour != data_round:
|
|
||||||
# On saute ce tour
|
|
||||||
continue
|
|
||||||
|
|
||||||
file = get_file(file_url, f"resultats-legislatives-2024-t{tour}-par-region.csv")
|
file = get_file(file_url, f"resultats-legislatives-2024-t{tour}-par-region.csv")
|
||||||
|
|
||||||
with file.open('r') as f:
|
with file.open('r') as f:
|
||||||
@ -572,15 +543,9 @@ def importer_resultats_region(engine: Engine, data_round: int = 0, verbose: bool
|
|||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
|
|
||||||
def importer_resultats_france(engine: Engine, data_round: int = 0, verbose: bool = False) -> None:
|
def importer_resultats_france(engine: Engine, verbose: bool = False) -> None:
|
||||||
# Erreur avec les données France Entière du 1er tour, qui sera j'espère corrigée un jour
|
tours = [(1, "https://www.data.gouv.fr/fr/datasets/r/386fd5ac-e7f1-4e0f-8929-12d2c5391081")]
|
||||||
tours = [# (1, "https://www.data.gouv.fr/fr/datasets/r/386fd5ac-e7f1-4e0f-8929-12d2c5391081"),
|
|
||||||
(2, "https://www.data.gouv.fr/fr/datasets/r/f64d2781-4ffa-414b-8f6d-e9d849f2f5e7")]
|
|
||||||
for tour, file_url in tours:
|
for tour, file_url in tours:
|
||||||
if data_round > 0 and tour != data_round:
|
|
||||||
# On saute ce tour
|
|
||||||
continue
|
|
||||||
|
|
||||||
file = get_file(file_url, f"resultats-legislatives-2024-t{tour}-france-entiere.csv")
|
file = get_file(file_url, f"resultats-legislatives-2024-t{tour}-france-entiere.csv")
|
||||||
|
|
||||||
with file.open('r') as f:
|
with file.open('r') as f:
|
||||||
@ -635,10 +600,10 @@ def importer_resultats_france(engine: Engine, data_round: int = 0, verbose: bool
|
|||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
|
|
||||||
def run(engine: Engine, data_round: int = 1, verbose: bool = False) -> None:
|
def run(engine: Engine, verbose: bool = False) -> None:
|
||||||
importer_resultats_france(engine, data_round, verbose)
|
importer_resultats_france(engine, verbose)
|
||||||
importer_resultats_region(engine, data_round, verbose)
|
importer_resultats_region(engine, verbose)
|
||||||
importer_resultats_departement(engine, data_round, verbose)
|
importer_resultats_departement(engine, verbose)
|
||||||
importer_resultats_circo(engine, data_round, verbose)
|
importer_resultats_circo(engine, verbose)
|
||||||
importer_resultats_commune(engine, data_round, verbose)
|
importer_resultats_commune(engine, verbose)
|
||||||
importer_resultats_bv(engine, data_round, verbose)
|
importer_resultats_bv(engine, verbose)
|
||||||
|
Loading…
Reference in New Issue
Block a user