Correction import circonscriptions

This commit is contained in:
Emmy D'Anello 2024-06-15 20:31:30 +02:00
parent ffc54be4fa
commit b97dc60f2a
Signed by: ynerant
GPG Key ID: 3A75C55819C8CF85

View File

@ -170,8 +170,9 @@ def importer_resultats_circo(engine: Engine, verbose: bool = False) -> None:
for row in tqdm(reader, desc="Circonscription", disable=not verbose): for row in tqdm(reader, desc="Circonscription", disable=not verbose):
circo_code = row['Code circonscription législative'] circo_code = row['Code circonscription législative']
dpt_code, circo_code = circo_code[:-2], circo_code[-2:] dpt_code, circo_code = circo_code[:-2], circo_code[-2:]
circo_id = f"{dpt_code.zfill(2)}-{circo_code.zfill(2)}"
resultats_circo = session.execute(select(ResultatsCirconscription).filter_by(circo_id=circo_code)) \ resultats_circo = session.execute(select(ResultatsCirconscription).filter_by(circo_id=circo_id)) \
.scalar_one_or_none() .scalar_one_or_none()
if not resultats_circo: if not resultats_circo:
resultats_dpt = session.execute(select(ResultatsDepartement) resultats_dpt = session.execute(select(ResultatsDepartement)
@ -202,10 +203,10 @@ def importer_resultats_circo(engine: Engine, verbose: bool = False) -> None:
resultats_dpt = session.execute(select(ResultatsDepartement) resultats_dpt = session.execute(select(ResultatsDepartement)
.filter_by(dpt_id=row['Code département'])).scalar_one() .filter_by(dpt_id=row['Code département'])).scalar_one()
resultats_circo = ResultatsCirconscription(circo_id=circo_code, resultats_circo = ResultatsCirconscription(circo_id=circo_id,
resultats_departement_id=resultats_dpt.id) resultats_departement_id=resultats_dpt.id)
session.add(resultats_circo) session.add(resultats_circo)
resultats_circo = session.execute(select(ResultatsCirconscription).filter_by(circo_id=circo_code)) \ resultats_circo = session.execute(select(ResultatsCirconscription).filter_by(circo_id=circo_id)) \
.scalar_one() .scalar_one()
resultats_circo.inscrits = int(row['Inscrits']) resultats_circo.inscrits = int(row['Inscrits'])