Pour des raisons de performance, on ne traite que les communes du 67
This commit is contained in:
parent
8d94230674
commit
3edfcbee19
@ -3,6 +3,7 @@ from pathlib import Path
|
||||
|
||||
from sqlalchemy import Engine, select
|
||||
from sqlalchemy.orm import Session
|
||||
from tqdm import tqdm
|
||||
|
||||
from nupes.models.geographie import Region, Departement, Commune
|
||||
from nupes.models.europeennes2024 import Bloc, Nuance, Liste, \
|
||||
@ -100,7 +101,7 @@ def exporter_resultats_regions(engine: Engine) -> None:
|
||||
regions = session.execute(select(Region)).scalars().all()
|
||||
regions_json = []
|
||||
|
||||
for region in regions:
|
||||
for region in tqdm(regions, desc="Régions"):
|
||||
region_json = {'code_insee': region.code_insee, 'nom': region.libelle,
|
||||
'departements': [dpt.code_insee for dpt in region.departements]}
|
||||
regions_json.append(region_json)
|
||||
@ -150,7 +151,7 @@ def exporter_resultats_departements(engine: Engine) -> None:
|
||||
departements = session.execute(select(Departement)).scalars().all()
|
||||
departements_json = []
|
||||
|
||||
for departement in departements:
|
||||
for departement in tqdm(departements, desc="Départements"):
|
||||
departement_json = {'code_insee': departement.code_insee, 'nom': departement.libelle,
|
||||
'region': departement.region_code,
|
||||
'communes': [commune.code_insee for commune in departement.communes]}
|
||||
@ -200,10 +201,11 @@ def exporter_resultats_departements(engine: Engine) -> None:
|
||||
|
||||
def exporter_resultats_communes(engine: Engine) -> None:
|
||||
with Session(engine) as session:
|
||||
communes = session.execute(select(Commune)).scalars().all()
|
||||
# FIXME On n'importe que les communes du Bas-Rhin pour des raisons de gain de temps
|
||||
communes = session.execute(select(Commune).filter_by(departement_code=67)).scalars().all()
|
||||
communes_json = []
|
||||
|
||||
for commune in communes:
|
||||
for commune in tqdm(communes, desc="Communes"):
|
||||
commune_json = {'code_insee': commune.code_insee, 'nom': commune.libelle,
|
||||
'departement': commune.departement_code,
|
||||
'bureaux_vote': [bv.id for bv in commune.bureaux_vote]}
|
||||
|
@ -170,7 +170,8 @@ def importer_resultats_departements(engine: Engine) -> None:
|
||||
|
||||
def importer_resultats_communes(engine: Engine) -> None:
|
||||
with Session(engine) as session:
|
||||
for commune in tqdm(session.execute(select(Commune)).scalars().all(), desc="Communes"):
|
||||
# FIXME On n'importe que les communes du Bas-Rhin pour des raisons de gain de temps
|
||||
for commune in tqdm(session.execute(select(Commune).filter_by(departement_code=67)).scalars().all(), desc="Communes"):
|
||||
reg_code = commune.departement.region_code
|
||||
reg_path = f"{reg_code}/"
|
||||
dpt_code = commune.departement_code
|
||||
|
Loading…
Reference in New Issue
Block a user