-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtracker.py
More file actions
executable file
·74 lines (56 loc) · 1.91 KB
/
Copy pathtracker.py
File metadata and controls
executable file
·74 lines (56 loc) · 1.91 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
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
#!/usr/bin/python3
import sqlite3
import datetime as dt
from datetime import datetime, timedelta
import yagmail
conn = sqlite3.connect('database.db')
plants = conn.execute('SELECT * FROM plants').fetchall()
garden = conn.execute('SELECT * from garden').fetchall()
today = dt.datetime.now()
temp = today.strftime('%Y-%m-%d')
thirsty = 'Thirsty plant bbs:\n\n'
email_list = "emailAddresses.txt"
thirsty_boi = "./static/thirstyBoy.png"
# Step through plants table and recalculate remaining days
for item in plants:
lastWatered = dt.datetime.strptime(item[2], '%Y-%m-%d')
delta = int(item[3])
daysSince = today - lastWatered
daysMod = daysSince.days
name = item[1]
timeLeft = delta - daysMod
if daysMod >= delta:
thirsty += str(item[1]) + """ bby says, "Please water me! It's been """ + str(daysMod) + " whole days!\"\n\n"
conn.execute('UPDATE plants SET remaining = ?, timeEllapsed = ? WHERE name = ?', (timeLeft, daysMod, name))
thirsty += "\n\nThirsty garden bbs:\n\n"
# Step through garden table and recalculate remaining days
for item in garden:
lastWatered = dt.datetime.strptime(item[2], '%Y-%m-%d')
delta = int(item[3])
daysSince = today - lastWatered
daysMod = daysSince.days
name = item[1]
timeLeft = delta - daysMod
if daysMod >= delta:
thirsty += str(item[1]) + """ bby says, "Please water me! It's been """ + str(daysMod) + " whole days!\"\n\n"
conn.execute('UPDATE garden SET remaining = ? WHERE name = ?', (timeLeft, name))
conn.commit()
conn.close()
with open(email_list) as f:
emailAddresses = f.readlines()
for i in emailAddresses:
print(i)
if thirsty != '':
for i in emailAddresses:
user = 'dpculler91@gmail.com'
password = 'fotdjuqwjkumhoqh'
to = i
subject = 'Plant Baby Alert!'
text = thirsty + '\n\n\n'
image = yagmail.inline(thirsty_boi)
contents = [text,image]
try:
yag = yagmail.SMTP(user,password)
yag.send(to,subject,contents)
except:
print('Oh noooo...')