forked from rohitrsharma3/Day-Planner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
backend.py
65 lines (58 loc) · 2.32 KB
/
backend.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
import smtplib
import csv
import datetime
from datetime import datetime as dt
import os
from tkinter import *
flag = True
def writeToLog(now):
with open('C:\\Users\\rohit\\Desktop\\Code\\Day-Planner\\log.txt', 'a') as log:
log.write('email sent at '+ str(now))
def checkTime():
global flag, backendroot
a = None
with open('C:\\Users\\rohit\\Desktop\\Code\\Day-Planner\\remindersData.csv','r') as file:
#csv_reader = csv.reader(file) #these lines cause errors but are not necessary
#next(csv_reader)
for line in file:
listLine = line.split(',')
startTime = listLine[-2]
date = listLine[0]
print('line', line)
now = dt.now().strftime('%d-%m-%y %H:%M')
if startTime == "N\A":
pass
else:
try:
if dt.strptime(date + " " + startTime, '%Y-%m-%d %H:%M') == dt.strptime(now, '%d-%m-%y %H:%M'):
print('found upcoming event at', date + " "+startTime)
mail('', '', line)
writeToLog(now)
try:
next(line)
except:
flag = False
break
except:
try:
next(line)
except:
print('ERROR')
flag = False
break
backendroot.after(1000,checkTime) #repeat checking process after x milliseconds for continuous background checking
def mail(From, to, body):
gmail_usr = ""
gmail_password = ""
server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
server.ehlo()
server.login(gmail_usr, gmail_password)
server.sendmail(From, to ,body)
server.close()
print("EMAIL SENT!!!!")
#while flag == True:
if __name__ == '__main__': #run this code only if this script is ran directly not when imported
backendroot = Tk() #define a tkinter window for using the after method
backendroot.withdraw() #make this window invisible as it is blank
checkTime() #run checktime function
backendroot.mainloop() #make window 'display' but is invisible