Skip to content
This repository was archived by the owner on Jan 20, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ Flask~=0.11.1
pep8~=1.7.0
pytest~=3.0.3
pytest-json~=0.4.0
git+https://github.com/startup-systems/splinter.git@ba3afc8a0750dcfea096f8f89adb58f8f8d78276#egg=splinter[flask]
splinter[flask]~=0.7.5
8 changes: 5 additions & 3 deletions squawker/schema.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
-- TODO change this
DROP TABLE IF EXISTS mytable;
CREATE TABLE mytable (id integer);
DROP TABLE IF EXISTS posts;
CREATE TABLE posts (
id INTEGER PRIMARY KEY AUTOINCREMENT,
msg VARCHAR(140) DEFAULT NULL
);
20 changes: 14 additions & 6 deletions squawker/server.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from flask import Flask, g
from flask import Flask, g, request, render_template, abort, redirect
import sqlite3


Expand Down Expand Up @@ -37,12 +37,20 @@ def close_connection(exception):
# ------------------------------


@app.route('/')
@app.route('/', methods=['GET', 'POST'])
def root():
conn = get_db()
# TODO change this
return "Hello World!"

c = conn.cursor()
if request.method == "POST":
txt = request.form["post"]
if len(txt) > 140:
abort(400)
else:
c.execute("INSERT INTO posts (msg) VALUES (?)", [txt])
conn.commit()
c.execute("SELECT msg FROM posts ORDER BY id DESC")
squawks = c.fetchall()
return render_template("index.html", rows=squawks)

if __name__ == '__main__':
app.run()
app.run(Debug=True)
28 changes: 28 additions & 0 deletions squawker/templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!DOCTYPE html>
<html>
<head>
<title>Squawker</title>
</head>
<body>
<h1 for="msg">Post All Squawks Here!</h1>
<div class="postMsg">
<form action="/" method="POST">
<div>
<textarea id="message" name="post" maxLength="140"></textarea>
</div>
<div class="button">
<button type="submit">Submit</button>
</div>
</form>
</div>
<br>
<div class="getMsg">
<label for="allPosts">Your posts:</label>
{% for post in rows %}
<div class="posts">
<p>{{ post[0] }}</p>
</div>
{% endfor %}
</div>
</body>
</html>