Commit d16522f1 authored by Nicolas Joyard's avatar Nicolas Joyard

Ajout importer pour maj emails

parent ebc29a27
......@@ -8,6 +8,7 @@ from flask_migrate import Migrate, MigrateCommand
from flask_script import Manager
from .importers.adresses import AdressesImporter
from .importers.emails import EmailImporter
from .importers.laposte import LaPosteImporter
from .importers.nosdeputes import NosDeputesImporter
......@@ -160,6 +161,16 @@ def import_laposte():
def import_emails():
Importe les emails des députés depuis un fichier DATA_DIR/emails.csv au
format "nom complet;email1,email2,..."
def password():
"""Chiffre un mot de passe admin"""
# -*- coding: utf-8 -*-
import csv
from os.path import join
from .base import BaseImporter
from ..models import Parlementaire, db
class NonTrouve(Exception):
class EmailImporter(BaseImporter):
def import_emails(self, nom, emails):
parl = Parlementaire.query.filter(Parlementaire.nom_complet == nom) \
if not parl:
raise NonTrouve('%s non trouvé' % nom)
if parl.emails != emails:'%s => %s' % (nom, emails))
parl.emails = emails
return True
return False
def run(self):'Début import emails')
erreurs = 0
changes = 0
with open(join(['DATA_DIR'], 'emails.csv'),
newline='') as csvfile:
reader = csv.DictReader(csvfile, delimiter=';')
for row in reader:
if self.import_emails(row['nom'], row['emails']):
changes = changes + 1
except NonTrouve:
self.error('Non trouvé: %s' % row['nom'])
erreurs = erreurs + 1'Import emails terminé, %s changements, %s erreurs' %
(changes, erreurs))
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment