-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse-mail-msg.py
More file actions
46 lines (30 loc) · 1.18 KB
/
Copy pathparse-mail-msg.py
File metadata and controls
46 lines (30 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import win32com.client
import glob
import os
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
path = os.path.dirname(os.path.abspath(__file__))
files = glob.glob('msgs/*.msg')
def get(str):
return str.split(':')[1].lstrip().rstrip()
print ('INSERT INTO `orcamentos` (`nome`, `telefone`, `email`, `estado`, `cidade`, `toneladas`, `cultivos`, `mensagem`, `ip`, `data`) VALUES')
msgs = []
for file in files:
msg = outlook.OpenSharedItem(path + '\\' + file)
lines = [line.lstrip().rstrip() for line in msg.Body.split('\n')]
nome = get(lines[2])
telefone = get(lines[3])
email = get(lines[4])
estado = get(lines[5])
cidade = get(lines[6])
toneladas = get(lines[7])
cultivos = get(lines[8])
last = lines[11] if 'Mensagem' in lines[9] else lines[10]
last = last.split('-')
dh = last[0].split(' as ')
d = dh[0].split('/')
data = d[2] + '-' + d[1] + '-' + d[0] + ' ' + dh[1].lstrip().rstrip()
ip = last[1].lstrip().rstrip()
msgs.append([nome, telefone, email, estado, cidade, toneladas, cultivos, ip, data])
for s in sorted(msgs, key=lambda x: x[8]):
print("('" + "','".join(s) + "'),")
del outlook, msg