diff --git a/squawker/schema.sql b/squawker/schema.sql index 5e67ffb..4110284 100644 --- a/squawker/schema.sql +++ b/squawker/schema.sql @@ -1,3 +1,2 @@ --- TODO change this -DROP TABLE IF EXISTS mytable; -CREATE TABLE mytable (id integer); +DROP TABLE IF EXISTS listOfSquawks; +CREATE TABLE listOfSquawks (id integer primary key, caption VARCHAR(140)); \ No newline at end of file diff --git a/squawker/server.py b/squawker/server.py index 6ff24ba..bcfb523 100644 --- a/squawker/server.py +++ b/squawker/server.py @@ -1,8 +1,8 @@ -from flask import Flask, g +from flask import Flask, g, request, render_template, abort import sqlite3 -# -- leave these lines intact -- +# -- leave these lines intact test-- app = Flask(__name__) @@ -37,12 +37,19 @@ def close_connection(exception): # ------------------------------ -@app.route('/') +@app.route('/', methods=["GET", "POST"]) def root(): conn = get_db() - # TODO change this - return "Hello World!" - + if request.method == "POST": + getCaption = request.form['caption'] + if len(getCaption) > 140: + abort(400) + else: + cc_object = conn.execute('INSERT INTO listOfSquawks (caption) VALUES (?)', [getCaption]) + conn.commit() + cc_object = conn.execute('SELECT * FROM listOfSquawks ORDER BY id desc') + squawkers = cc_object.fetchall() + return render_template('index.html', captions=squawkers) if __name__ == '__main__': app.run() diff --git a/squawker/templates/index.html b/squawker/templates/index.html new file mode 100644 index 0000000..a63a687 --- /dev/null +++ b/squawker/templates/index.html @@ -0,0 +1,28 @@ + + + + Elya's squawker assignment + + +
+
+
+ +
+
+
+ +
+
+
+ +
+ + {% for msg in captions %} +
+

{{ msg[1] }}

+
+ {% endfor %} +
+ + \ No newline at end of file