Commit 52f4d92e authored by Nicolas Joyard's avatar Nicolas Joyard

Extract 2

parent 15360c16
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from datetime import datetime, timedelta from datetime import datetime, timedelta
import dateparser
import email import email
import os import os
import re import re
...@@ -240,6 +241,7 @@ def extraire_mails_cada(app): ...@@ -240,6 +241,7 @@ def extraire_mails_cada(app):
with open(os.path.join(emails_root, eml)) as f: with open(os.path.join(emails_root, eml)) as f:
message = email.message_from_file(f) message = email.message_from_file(f)
cada_id = message['subject'] cada_id = message['subject']
date_avis = dateparser.parse(message['date'].replace(" (CET)", "")
# Extraction pièce jointe 'Avis.pdf' # Extraction pièce jointe 'Avis.pdf'
pdf = None pdf = None
...@@ -297,6 +299,10 @@ def extraire_mails_cada(app): ...@@ -297,6 +299,10 @@ def extraire_mails_cada(app):
if act.attachment != pdfbase: if act.attachment != pdfbase:
print('CADA %s; (!) 2ème avis CADA (existant: %s)' print('CADA %s; (!) 2ème avis CADA (existant: %s)'
% (cada_id, pdfbase)) % (cada_id, pdfbase))
if act.date != date_avis:
act.date = date_avis
db.session.add(act)
db.session.commit()
continue continue
print('CADA %s; Ajout avis CADA pour %s' print('CADA %s; Ajout avis CADA pour %s'
......
...@@ -10,7 +10,7 @@ from ..models.constants import (DEBUT_ACTION, ETAPE_A_CONFIRMER, ...@@ -10,7 +10,7 @@ from ..models.constants import (DEBUT_ACTION, ETAPE_A_CONFIRMER,
ETAPE_COURRIEL, ETAPES_BY_ORDRE, ETAPE_COURRIEL, ETAPES_BY_ORDRE,
ETAPE_DEMANDE_CADA, ETAPE_DOC_PUBLIE, ETAPE_DEMANDE_CADA, ETAPE_DOC_PUBLIE,
ETAPE_REPONSE_NEGATIVE, ETAPE_REPONSE_NEGATIVE,
ETAPE_DOC_MASQUE, ETAPE_AR_RECU, ETAPE_DOC_MASQUE, ETAPE_ENVOYE,
ETAPE_REPONSE_POSITIVE, ETAPE_NA) ETAPE_REPONSE_POSITIVE, ETAPE_NA)
from .mails import envoyer_alerte from .mails import envoyer_alerte
...@@ -121,7 +121,7 @@ def export_pour_ta(app): ...@@ -121,7 +121,7 @@ def export_pour_ta(app):
.order_by(Parlementaire.nom) \ .order_by(Parlementaire.nom) \
.all() .all()
output_order = ['num', 'nom', 'sexe', 'refus', 'demande', 'ar', output_order = ['num', 'nom', 'sexe', 'refus', 'demande', 'bordereau',
'avis_cada'] 'avis_cada']
print(';'.join(output_order)) print(';'.join(output_order))
...@@ -139,8 +139,8 @@ def export_pour_ta(app): ...@@ -139,8 +139,8 @@ def export_pour_ta(app):
} }
for act in parl.actions: for act in parl.actions:
if act.etape == ETAPE_AR_RECU: if act.etape == ETAPE_ENVOYE:
data['ar'] = act.attachment data['bordereau'] = act.attachment
if act.etape == ETAPE_REPONSE_NEGATIVE: if act.etape == ETAPE_REPONSE_NEGATIVE:
data['refus'] = 'REFUS' data['refus'] = 'REFUS'
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment