Created
January 23, 2012 22:30
-
-
Save RobSpectre/1665858 to your computer and use it in GitHub Desktop.
SMS Birthday Card Step 4: Add a HELP keyword.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask | |
from flask import request | |
import os | |
from random import choice | |
from twilio import twiml | |
app = Flask(__name__) | |
@app.route('/sms', methods=['POST']) | |
def sms(): | |
r = twiml.Response() | |
reason = reasonSonyaIsAwesome() | |
if request.form['Body'].upper() == "HELP": | |
r.sms("Welcome to the Reasons Sonya Is Awesome Hotline. Text GIMME " \ | |
"to get one random reason Sonya is awesome.") | |
else: | |
r.sms(reason) | |
return str(r) | |
def reasonSonyaIsAwesome(): | |
reasons = [ | |
'Alex: You hate the Giants.', | |
'Kent: You have a great sense of humor.', | |
'Ellen: Your brain is is awesome.', | |
'Becca: You are a good listener and has a fantastic perspective.', | |
'Rob: Your family comes first.', | |
'Bill: You speak Russian. LOUD.'] | |
return choice(reasons) | |
if __name__ == '__main__': | |
port = int(os.environ.get('PORT', 5000)) | |
if port == 5000: | |
app.debug = True | |
app.run(host='0.0.0.0', port=port) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment