File size: 1,917 Bytes
48158b4 |
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 |
from flask import Flask, request
from twilio.twiml.messaging_response import MessagingResponse
from gsheet_func import *
from dateutil.parser import parse
app = Flask(__name__)
count=0
@app.route("/sms", methods=['POST'])
def reply():
incoming_msg = request.form.get('Body').lower()
response = MessagingResponse()
message=response.message()
responded = False
words = incoming_msg.split('@')
if "hello" in incoming_msg:
reply = "Hello! \nDo you want to set a reminder?"
message.body(reply)
responded = True
if len(words) == 1 and "yes" in incoming_msg:
reminder_string = "Please provide date in the following format only.\n\n"\
"*Date @* _type the date_ "
message.body(reminder_string)
responded = True
if len(words) == 1 and "no" in incoming_msg:
reply="Ok. Have a nice day!"
message.body(reply)
responded = True
elif len(words) != 1:
input_type = words[0].strip().lower()
input_string = words[1].strip()
if input_type == "date":
reply="Please enter the reminder message in the following format only.\n\n"\
"*Reminder @* _type the message_"
set_reminder_date(input_string)
message.body(reply)
responded = True
if input_type == "reminder":
reply="Your reminder is set!"
set_reminder_body(input_string)
message.body(reply)
responded = True
if not responded:
message.body('Incorrect request format. Please enter in the correct format')
return str(response)
def set_reminder_date(msg):
p= parse(msg)
date=p.strftime('%d/%m/%Y')
save_reminder_date(date)
return 0
def set_reminder_body(msg):
save_reminder_body(msg)
return 0
if __name__ == "__main__":
app.run(debug=True)
|