/
app.py
53 lines (34 loc) · 1.42 KB
/
app.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
### Modules ################################
import sys, re
from flask import Flask, request
from twilio.rest import TwilioRestClient
import twilio.twiml
import game
### App Config ########################################################################
app = Flask(__name__)
### Key / Passwords File ###
app.config.from_pyfile('keys.cfg')
### Twilio Stuff ###
account_sid = app.config['TWIL_SID']
auth_token = app.config['TWIL_TOKEN']
twil_number = app.config['TWILIO_NUMBER']
twilio_client = TwilioRestClient(account_sid, auth_token)
### save path ####################################################################
save_dir = sys.path[0]
### App Views ####################################################################
@app.route("/", methods=['GET','POST'])
def index():
app_title = "txtr engine"
return render_template('index.html', app_title=app_title)
@app.route("/sms", methods=['GET', 'POST'])
def accept_response():
from_number = request.values.get('From') # get the from number
raw = request.values.get('Body') # get the body of the text message
body = re.sub(r'[^\w\s]','',raw) # strip all the punctuation out of the message.
g = game.Game(twilio_client, from_number, twil_number, save_dir)
g.take_action(body) # pass the body to the take action function
g.save() # save this in a file
resp = twilio.twiml.Response()
return str(resp)
if __name__ == "__main__":
app.run(debug=True)