Correction import résultats Saint-Martin/Saint-Barthélémy
This commit is contained in:
parent
18092fbb09
commit
ab9267cb13
@ -102,16 +102,20 @@ def importer_resultats_commune(engine: Engine, verbose: bool = False) -> None:
|
||||
with Session(engine) as session:
|
||||
for row in tqdm(reader, desc="Commune", disable=not verbose):
|
||||
com_code = str(row['Code commune']).zfill(5)
|
||||
dpt_code = row['Code département']
|
||||
|
||||
if dpt_code == "ZX":
|
||||
dpt_code = "977"
|
||||
|
||||
resultats_commune = session.execute(select(ResultatsCommune).filter_by(commune_id=com_code)) \
|
||||
.scalar_one_or_none()
|
||||
if not resultats_commune:
|
||||
resultats_dpt = session.execute(select(ResultatsDepartement)
|
||||
.filter_by(dpt_id=row['Code département'])) \
|
||||
.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)}")) \
|
||||
.filter_by(code_insee=f"{dpt_code.zfill(2)}")) \
|
||||
.scalar_one()
|
||||
resultats_reg = session.execute(select(ResultatsRegion)
|
||||
.filter_by(region_id=dpt.region_code)) \
|
||||
@ -128,11 +132,11 @@ def importer_resultats_commune(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_commune = ResultatsCommune(commune_id=com_code, resultats_dpt_id=resultats_dpt.id)
|
||||
session.add(resultats_commune)
|
||||
|
Loading…
Reference in New Issue
Block a user