Last active
August 29, 2015 13:56
-
-
Save straup/8919714 to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/env python | |
# see also: | |
# https://www.twilio.com/ | |
# https://www.heroku.com/ | |
# https://devcenter.heroku.com/articles/getting-started-with-python#declare-process-types-with-procfile | |
# https://devcenter.heroku.com/articles/config-vars | |
# https://devcenter.heroku.com/articles/logging#log-retrieval | |
import sys | |
import os | |
from flask import Flask, request, redirect | |
from twilio import twiml | |
import cooperhewitt.api.client | |
# https://collection.cooperhewitt.org/api/oauth2/authenticate/like-magic/ | |
# heroku config:set CH_API_KEY=<ACCESS TOKEN> | |
token = os.environ['CH_API_KEY'] | |
app = Flask(__name__) | |
@app.route('/', methods=['GET', 'POST']) | |
def voice(): | |
wazzup = sayit() | |
r = twiml.Response() | |
r.say(wazzup) | |
return str(r) | |
@app.route('/sms', methods=['GET','POST']) | |
def sms(): | |
wazzup = sayit() | |
r = twiml.Response() | |
r.sms(wazzup) | |
return str(r) | |
def sayit(): | |
api = cooperhewitt.api.client.OAuth2(token) | |
rsp = api.call('cooperhewitt.labs.whatWouldMicahSay') | |
micah = rsp['micah'] | |
says = micah['says'] | |
return says | |
if __name__ == '__main__': | |
if not os.environ.get('CH_API_KEY', False): | |
print "You forgot to set your CH API key as an environment variable" | |
sys.exit() | |
rsp = sms() | |
print rsp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment