-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInternationalLiaison.py
79 lines (68 loc) · 4.06 KB
/
InternationalLiaison.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import csv, smtplib, ssl, xlrd, openpyxl, datetime, subprocess, argparse, n2w
import gmailapppassword
from_address = gmailapppassword.username
password = gmailapppassword.password
now = datetime.datetime.now()
exceltup = (now.year, now.month, now.day)
today = int(xlrd.xldate.xldate_from_date_tuple((exceltup),0))
tomorrow = today + 1
dayleavingtext = "in two days"
intwodays = today + 2
inthreedays = today + 3
with open("email.csv",encoding="utf-8-sig") as file:
reader = csv.DictReader(file)
for row in reader:
if row['International Section'] == "IL":
to_address = row['InternationalLiaisonEmail']
subject = "Subject: Trips with International Campers" + "\n\n"
standardmessage = "Hi " + row['InternationalLiaisonName'] + ","
signoff = "\n\nSincerely,\n\nStu"
with open("email.csv",encoding="utf-8-sig") as file:
reader = csv.DictReader(file)
trips = "\n\nHere are the trips in your section that have changed since the last trip schedule:"
LITneeded = ""
for row in reader:
if row['International Section'] == "IL" and row['Changed Since Last Version'] == "Yes" and row['Session'].startswith('B') and not row['Trip Status'] == "Done" and not row['Trip Status'] == "Out":
xlstartdate = xlrd.xldate_as_datetime(int(row['Start Date']), 0).strftime("%b. %d")
xlenddate = xlrd.xldate_as_datetime(int(row['End Date']), 0).strftime("%b. %d")
if int(row['Total People on Trip']) % 2 == 0 and not row['Trip Program'] == "PJ":
LITneeded = ""
else:
LITneeded = "\nLIT Needed"
if row['Cabin'] == "0" or row['Cabin'] == 0 or row['Cabin'] == "":
cabin = ""
else:
cabin = "\n" + row['Cabin'] + ":"
trips += "\n\n" + '{:0>3}'.format(row['TripID']) + " " + row['Route'] +"\n" + xlstartdate + " to " + xlenddate + "\n" + "Tripper: " + row['Tripper 1'] + "\n" + "Staff: " + row['Staff List for Trip Program'] + LITneeded + "\n" + cabin + "\n"
for i in range(1, 30):
if row['Camper ' + str(i)] != "" and "- I" in row['Camper ' +str(i)]:
trips += row['Camper ' + str(i)] + "\n"
else:
trips += ""
with open("email.csv",encoding="utf-8-sig") as file:
reader = csv.DictReader(file)
unchangedtrips = "\n\nAnd these are the trips in your section that have not changed since the last trip schedule:"
unchangedLITneeded = ""
for row in reader:
if row['International Section'] == "IL" and row['Changed Since Last Version'] == "" and row['Session'].startswith('B') and not row['Trip Status'] == "Done" and not row['Trip Status'] == "Out":
xlstartdate = xlrd.xldate_as_datetime(int(row['Start Date']), 0).strftime("%b. %d")
xlenddate = xlrd.xldate_as_datetime(int(row['End Date']), 0).strftime("%b. %d")
if int(row['Total People on Trip']) % 2 == 0 and not row['Trip Program'] == "PJ":
unchangedLITneeded = ""
else:
unchangedLITneeded = "\nLIT Needed"
if row['Cabin'] == "0" or row['Cabin'] == 0 or row['Cabin'] == "":
cabin = ""
else:
cabin = "\n" + row['Cabin'] + ":"
unchangedtrips += "\n\n" + '{:0>3}'.format(row['TripID']) + " " + row['Route'] +"\n" + xlstartdate + " to " + xlenddate + "\n" + "Tripper: " + row['Tripper 1'] + "\n" + "Staff: " + row['Staff List for Trip Program'] + unchangedLITneeded + "\n" + cabin + "\n"
for i in range(1, 30):
if row['Camper ' + str(i)] != "" and "- I" in row['Camper ' +str(i)]:
unchangedtrips += row['Camper ' + str(i)] + "\n"
else:
unchangedtrips += ""
context = ssl.create_default_context()
with smtplib.SMTP_SSL("smtp.gmail.com", 465, context=context) as server:
server.login(from_address,password)
coremessage = subject+standardmessage+trips+unchangedtrips+signoff
server.sendmail(from_address,to_address,coremessage.encode('utf-8'))