-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
53 lines (46 loc) · 1.35 KB
/
server.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
from flask import Flask
from flask_mail import Message,Mail
from datetime import date,timedelta
import pymongo
from bson import json_util
import json
from privacy import mongoConnString,myMail,emailPassword
app = Flask(__name__)
mail = Mail(app)
app.config['MAIL_SERVER']='smtp.gmail.com'
app.config['MAIL_PORT'] = 465
app.config['MAIL_USERNAME'] = myMail
app.config['MAIL_PASSWORD'] = emailPassword
app.config['MAIL_USE_TLS'] = False
app.config['MAIL_USE_SSL'] = True
mail = Mail(app)
url = mongoConnString
client = pymongo.MongoClient(url)
Database = client.get_database('notify')
if Database :
print("!!database connected!!")
TaskTable = Database.TaskTable
def sendEmail(recievers,message):
msg = Message(
'Notify',
sender= myMail,
recipients=[recievers]
)
msg.body = message+' due tommorrow!!'
mail.send(msg)
@app.route('/')
def email():
today = date.today()
tomorrow = today + timedelta(1)
query = TaskTable.find({"Date" : str(tomorrow)})
obj = json.loads(json_util.dumps(query))
taskArray = []
for i in obj :
if(i['IsSent'] == False) :
sendEmail(i['Email'],i['Task'])
filter = {'Task' : i['Task']}
newValues = {"$set" : {'IsSent' : True}}
TaskTable.update_one(filter,newValues)
return "sent"
if __name__ == '__main__':
app.run(debug=True)