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
5 changes: 4 additions & 1 deletion squawker/schema.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
-- TODO change this
DROP TABLE IF EXISTS mytable;
CREATE TABLE mytable (id integer);
CREATE TABLE mytable (
message VARCHAR DEFAULT NULL,
time VARCHAR
);
19 changes: 16 additions & 3 deletions squawker/server.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from flask import Flask, g
from flask import Flask, g, abort, request, render_template
import sqlite3
import time


# -- leave these lines intact --
Expand Down Expand Up @@ -37,11 +38,23 @@ 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':
squawk = request.form['message']
time_posted = time.ctime(int(time.time()))
if len(squawk) > 140:
abort(400)
else:
squawks = (squawk, time_posted)
c.execute('INSERT INTO mytable VALUES (?, ?)', squawks)
conn.commit()
c.execute('SELECT message FROM mytable ORDER BY time DESC')
posts = c.fetchall()
return render_template('index.html', allpost=posts)


if __name__ == '__main__':
Expand Down
27 changes: 27 additions & 0 deletions squawker/static/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
p {}

form {
top: 20px;
margin: 0 auto;
width: 600px;
padding: 5em;
border-radius: 2em;
}

div.allposts {
margin: 0px 30px 20px 330px;
}

textarea {
font: 1em sans-serif;
vertical-align: top;
height: 5em;
width: 600px;
border: 4px solid #000000;
}

button {
height: 30px;
width: 120px;
}

27 changes: 27 additions & 0 deletions squawker/templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!DOCTYPE html5>
<html>
<head>
<title>squawker</title>
<link rel="stylesheet" href="static/index.css">
</head>
<body>

<form action="/" method="POST">
<div>
<label>Creat New Squawker</label>
<textarea name="message" type="text" maxlength="140" required></textarea>
</div>
<div class="button">
<button type="submit">Post New Squawk</button>
</div>
</form>

{% for post in allpost %}
<div class="allposts">
<p>{{ post[0] }}<br>
{{ post[1] }}<p>
</div>
{% endfor %}

</body>
</html>