Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
46 lines (35 sloc) 1.21 KB
from flask import Flask, request, make_response, render_template
import json
import urlparse
import os
import don
import don.memory.redisbacked
app = Flask(__name__)
url = urlparse.urlparse(os.environ.get('REDISTOGO_URL', 'redis://localhost:6379'))
mem = don.memory.redisbacked.Memory({'host':url.hostname, 'port':url.port, 'db':0, 'password': url.password})
bot = don.Don(mem)
for f in ['swear', 'don', 'hello', 'jokes', 'clever', 'lastresort']:
with open('brains/%s.json' % f, 'r') as handle:
def index():
return render_template('index.html')
def chat():
body = request.args.get('body')
convo = request.args.get('conversation')
if not body:
resp = make_response("body is required", 400)
if not convo:
resp = make_response("conversation is required", 400)
reply = bot.converse(body, convo)
if reply:
resp = make_response(reply, 200)
resp = make_response("That does not compute.", 200)
resp.headers['Content-Type'] = 'text/plain'
return resp
if __name__ == "__main__":