-
Notifications
You must be signed in to change notification settings - Fork 0
/
gonuts.py
47 lines (36 loc) · 1.35 KB
/
gonuts.py
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 smtplib
import csv
import email
from email.message import EmailMessage
import unicodedata
from unidecode import unidecode
from email.mime.text import MIMEText
def receipt_data():
with open('', mode='r', ) as data:
#expected format:
#me myself,mbilichenko@llnw.com,1360
reader = data.read()
#normalize ASCII
n = unicodedata.normalize('NFKD', reader)
#remove abundant new lines and make it a list of strings
r = n.replace('\n', ',')[:-1].split(',')
#make a list of tuple of every 3 items
l = list(zip(*[iter(r)] * 3))
#make a dict with 2 values
d = {a: (b, c) for a, b, c in l}
return d
def send_email():
server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login("", "")
buyers_dict = receipt_data()
for buyer in buyers_dict:
msg = 'Hi {0}, here is your amount due: {1}grn'.format(unidecode(buyer), buyers_dict[buyer][1])
message = 'Subject: {0}\n\n{1}'.format('Nuts receipt', msg)
server.sendmail(from_addr="bigfreshnuts@gmail.com", to_addrs=buyers_dict[buyer][0], msg=message)
# server.sendmail("bigfreshnuts@gmail.com", buyer, '''\
# Subject: test
#
# {0} , your amount due is: {1}
# '''.format(buyers_dict[buyer][0], buyers_dict[buyer][1]))
send_email()