Permalink
Browse files

Give Don a simple web interface.

  • Loading branch information...
1 parent 20580e2 commit a360c39e7a123dcad8215abc63722e31a00eac07 @jmhobbs jmhobbs committed May 15, 2012
Showing with 77 additions and 2 deletions.
  1. +5 −2 app.py
  2. +25 −0 static/chat.js
  3. BIN static/don.png
  4. +24 −0 static/style.css
  5. +23 −0 templates/index.html
View
7 app.py
@@ -1,5 +1,4 @@
-from flask import Flask
-from flask import request, make_response
+from flask import Flask, request, make_response, render_template
import json
@@ -16,6 +15,10 @@
bot.loadBrain(json.loads(handle.read()));
@app.route("/")
+def index():
+ return render_template('index.html')
+
+@app.route("/chat.txt")
def chat():
body = request.args.get('body')
convo = request.args.get('conversation')
View
@@ -0,0 +1,25 @@
+jQuery(document).ready( function ( $ ) {
+ var $body = $("#body"),
+ $send = $("#send"),
+ $mesg = $("#messages");
+
+ $send.click( function () {
+ var val = $body.val().replace( /^\s+|\s+$/g, '' );
+ if( val.length <= 0 ) { return; }
+ $body.val('');
+ $mesg.append( $('<div/>').addClass('me').text(val) );
+ $.get(
+ '/chat.txt',
+ { conversation: 'lol', body: val }
+ ).success( function ( data ) {
+ $mesg.append( $('<div/>').addClass('don').text(data) );
+ } ).error( function ( xhr ) {
+ $mesg.append( $('<div/>').addClass('don').text('ERROR!') );
+ } );
+ $body.focus();
+ } );
+
+ $body.keypress( function ( e ) {
+ if( e.which == 13 ) { $send.click(); return false; }
+ } );
+} );
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
@@ -0,0 +1,24 @@
+.wrapper {
+ width: 90%;
+ max-width: 500px;
+ margin: 0 auto;
+}
+
+.wrapper img {
+ width: 100%;
+}
+
+.wrapper input {
+ width: 100%;
+ display: block;
+ margin: 5px 0;
+}
+
+.don, .me {
+ margin: 3px 0;
+ border-bottom: 1px solid #999;
+}
+
+.don {
+ text-align: right;
+}
View
@@ -0,0 +1,23 @@
+<!DOCTYPE html>
+<html lang="en">
+ <head>
+ <meta charset="utf-8">
+ <!-- Made with Joy by What Cheer ♥ http://whatcheer.com -->
+ <title>Don the Robot</title>
+ <link rel="stylesheet" href="/static/style.css" type="text/css" media="all" />
+ <!--[if lt IE 9]>
+ <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
+ <![endif]-->
+ <link rel="shortcut icon" href="/static/favicon.ico" type="image/png" />
+ <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=yes"/>
+ </head>
+ <body onload="setTimeout(function(){window.scrollTo(0,1)},100);">
+ <div class="wrapper">
+ <img src="/static/don.png" alt="Don" />
+ <div id="messages"></div>
+ <input type="text" value="Hello!" name="body" id="body" /><input type="submit" value="Send" id="send" />
+ </div>
+ <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
+ <script src="/static/chat.js"></script>
+ </body>
+</html>

0 comments on commit a360c39

Please sign in to comment.