Skip to content
This repository was archived by the owner on Jan 20, 2025. It is now read-only.
Open

ok #57

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
Binary file added .DS_Store
Binary file not shown.
Binary file added squawker/.DS_Store
Binary file not shown.
6 changes: 4 additions & 2 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 squawktable;
CREATE TABLE squawktable (id INTEGER PRIMARY KEY AUTOINCREMENT,
message VARCHAR(140) DEFAULT NULL,
createTime TIMESTAMP DEFAULT CURRENT_TIMESTAMP);
17 changes: 13 additions & 4 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
import sqlite3


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


@app.route('/')
@app.route('/', methods=["POST", "GET"])
def root():
conn = get_db()
# TODO change this
return "Hello World!"
if request.method == "POST":
newmsg = request.form["user_post"]
if len(newmsg) > 140:
return "Post length error", 400
else:
conn.execute("INSERT INTO squawktable (message) VALUES(?)", [newmsg])
conn.commit()
c = conn.cursor()
c.execute("SELECT * FROM squawktable ORDER BY createTime DESC")
msgPool = c.fetchall()
return render_template("squawker.html", msgPool=msgPool)


if __name__ == '__main__':
Expand Down
25 changes: 25 additions & 0 deletions squawker/templates/squawker.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

<!DOCTYPE html>
<html>
<head>
<title>Squawker</title>
</head>
<body>
<form method="POST">
<div>
<label for="newmsg">Post Your Squawker</label>
<textarea maxlength="140" id="message" name="user_post"></textarea>
</div>
<div class="button">
<button type="submit">Post it!</button>
</div>
</form>
<div>
<ul id="message">
{% for msg in msgPool %}
<li>{{msg}}</li>
{% endfor %}
</ul>
</div>
</body>
</html>