-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
35 lines (29 loc) · 922 Bytes
/
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
from flask import Flask, request
from twilio import twiml
import helper
app = Flask(__name__)
#Set method call location on /sms post request
@app.route('/sms', methods=['POST'])
def sms():
number = request.form['From']
message_body = request.form['Body']
body=message_body.split()
body.append("error")
#Generate the correct response based on user's message
message= {
'about': "helper.get_help()",
'today': "helper.get_contributions(body[0])",
'streak': "helper.get_streak(body[0])",
'total': "helper.get_total(body[0])"
}.get(body[-2].lower(), "helper.get_error(body[-2])")
message=eval(message)
#Check for help
if(body[0]=="help"):
message=helper.get_help()
#Generate Twilio Response
resp = twiml.Response()
#Respond to SMS
resp.message(message)
return str(resp)
if __name__ == '__main__':
app.run() #Start the flask app