Mercurial > hg > bnpparibas
comparison bnpparibas.py @ 12:4747393db602
Decode messages send time and provide a nicer representation in emails
author | Daniele Nicolodi <daniele@grinta.net> |
---|---|
date | Mon, 11 Jan 2016 21:15:53 +0100 |
parents | f3d6d73a7184 |
children | 37ce0dc68cad |
comparison
equal
deleted
inserted
replaced
11:f3d6d73a7184 | 12:4747393db602 |
---|---|
11 import sys | 11 import sys |
12 import textwrap | 12 import textwrap |
13 import time | 13 import time |
14 | 14 |
15 from contextlib import contextmanager | 15 from contextlib import contextmanager |
16 from datetime import datetime | |
16 from email.mime.text import MIMEText | 17 from email.mime.text import MIMEText |
17 from email.utils import format_datetime, localtime, parseaddr | 18 from email.utils import format_datetime, localtime, parseaddr |
18 from io import BytesIO | 19 from io import BytesIO |
19 from pprint import pprint | 20 from pprint import pprint |
20 from urllib.parse import urljoin | 21 from urllib.parse import urljoin |
27 | 28 |
28 # message template | 29 # message template |
29 MESSAGE = """\ | 30 MESSAGE = """\ |
30 From: {message.sender:} | 31 From: {message.sender:} |
31 Subject: {message.subject:} | 32 Subject: {message.subject:} |
32 Date: {message.date:} | 33 Date: {message.date:%a, %d %b %Y %H:%M:%S} |
33 | 34 |
34 {message.body:} | 35 {message.body:} |
35 """ | 36 """ |
36 | 37 |
37 # transactions table row template | 38 # transactions table row template |
161 self.quoted = quoted | 162 self.quoted = quoted |
162 | 163 |
163 @classmethod | 164 @classmethod |
164 def fromjson(cls, x): | 165 def fromjson(cls, x): |
165 data = {'id': x['msg']['id'], | 166 data = {'id': x['msg']['id'], |
166 'date': x['msg']['id'], | 167 'date': datetime.strptime(x['msg']['id'], '%Y-%m-%d-%H.%M.%S.%f'), |
167 'subject': x['msg']['objet'], | 168 'subject': x['msg']['objet'], |
168 'sender': x['msg']['emetteur']['nom'], | 169 'sender': x['msg']['emetteur']['nom'], |
169 'content': x['msg']['contenu'], | 170 'content': x['msg']['contenu'], |
170 'quoted': None, } | 171 'quoted': None, } |
171 quoted = x.get('msgAttache') | 172 quoted = x.get('msgAttache') |