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
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 squawks;
CREATE TABLE squawks (
id INTEGER PRIMARY KEY AUTOINCREMENT,
squawk VARCHAR(140),
time_stamp DATETIME);
22 changes: 17 additions & 5 deletions squawker/server.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from flask import Flask, g
from flask import Flask, request, g, abort, render_template
import sqlite3

import os
import datetime

# -- leave these lines intact --
app = Flask(__name__)
Expand Down Expand Up @@ -37,11 +38,22 @@ def close_connection(exception):
# ------------------------------


@app.route('/')
@app.route('/', methods=['POST', 'GET'])
def root():
conn = get_db()
# TODO change this
return "Hello World!"
cursor = conn.cursor()
if request.method == "POST":
msg = request.form["content"]
if len(msg) <= 140:
query = "INSERT INTO squawks (squawk, time_stamp) VALUES (?, ?)"
time = datetime.datetime.now()
cursor.execute(query, (msg, time))
conn.commit()
else:
abort(400)
cursor.execute("SELECT squawk FROM squawks ORDER BY time_stamp DESC")
res = cursor.fetchall()
return render_template("index.html", squawks=res)


if __name__ == '__main__':
Expand Down
18 changes: 18 additions & 0 deletions squawker/templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Squawker</title>
</head>

<body>
<h1>Enter Squawkers Here</h1>
<form method="post">
<textarea name="content" maxlength="140" placeholder="Say something..."></textarea>
<input type="submit">
<h2>Your squawks:</h2>
{% for s in squawks %}
<p>{{s[0]}}</p>
{% endfor %}
</form>
</body>
</html>
1 change: 0 additions & 1 deletion tests/test_squawker.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import string
import tempfile
import time
from . import flaskclient_fix


URL = '/'
Expand Down