Correction Saint-Martin/Saint-Barthélémy
This commit is contained in:
parent
b97dc60f2a
commit
18092fbb09
|
@ -170,17 +170,19 @@ def importer_resultats_circo(engine: Engine, verbose: bool = False) -> None:
|
|||
for row in tqdm(reader, desc="Circonscription", disable=not verbose):
|
||||
circo_code = row['Code circonscription législative']
|
||||
dpt_code, circo_code = circo_code[:-2], circo_code[-2:]
|
||||
|
||||
if dpt_code == "ZX":
|
||||
dpt_code = "977"
|
||||
|
||||
circo_id = f"{dpt_code.zfill(2)}-{circo_code.zfill(2)}"
|
||||
|
||||
resultats_circo = session.execute(select(ResultatsCirconscription).filter_by(circo_id=circo_id)) \
|
||||
.scalar_one_or_none()
|
||||
if not resultats_circo:
|
||||
resultats_dpt = session.execute(select(ResultatsDepartement)
|
||||
.filter_by(dpt_id=row['Code département'])) \
|
||||
resultats_dpt = session.execute(select(ResultatsDepartement).filter_by(dpt_id=dpt_code)) \
|
||||
.scalar_one_or_none()
|
||||
if not resultats_dpt:
|
||||
dpt = session.execute(select(Departement)
|
||||
.filter_by(code_insee=f"{row['Code département'].zfill(2)}")) \
|
||||
dpt = session.execute(select(Departement).filter_by(code_insee=f"{dpt_code.zfill(2)}")) \
|
||||
.scalar_one()
|
||||
resultats_reg = session.execute(select(ResultatsRegion)
|
||||
.filter_by(region_id=dpt.region_code)) \
|
||||
|
@ -197,11 +199,11 @@ def importer_resultats_circo(engine: Engine, verbose: bool = False) -> None:
|
|||
resultats_reg = session.execute(select(ResultatsRegion)
|
||||
.filter_by(region_id=dpt.region_code)).scalar_one()
|
||||
|
||||
resultats_dpt = ResultatsDepartement(dpt_id=row['Code département'],
|
||||
resultats_dpt = ResultatsDepartement(dpt_id=dpt_code,
|
||||
resultats_region_id=resultats_reg.id)
|
||||
session.add(resultats_dpt)
|
||||
resultats_dpt = session.execute(select(ResultatsDepartement)
|
||||
.filter_by(dpt_id=row['Code département'])).scalar_one()
|
||||
.filter_by(dpt_id=dpt_code)).scalar_one()
|
||||
|
||||
resultats_circo = ResultatsCirconscription(circo_id=circo_id,
|
||||
resultats_departement_id=resultats_dpt.id)
|
||||
|
|
Loading…
Reference in New Issue