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
4 changes: 3 additions & 1 deletion 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);
CREATE TABLE mytable (
id integer primary key autoincrement,
posts text not null);
27 changes: 23 additions & 4 deletions squawker/server.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from flask import Flask, g
from flask import Flask, request, g, session, redirect, url_for, abort, render_template, flash
import sqlite3


# -- leave these lines intact --
app = Flask(__name__)
app.config.from_object(__name__)
app.secret_key = "super secret key"


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


@app.route('/')
@app.route('/', methods=['POST', 'GET'])
def root():
conn = get_db()
# TODO change this
return "Hello World!"
cur = conn.cursor()
conts = cur.execute('SELECT posts From mytable ORDER BY ID DESC')
posts = conts.fetchall()
return render_template('index.html', posts=posts)


@app.route('/add', methods=['POST', 'GET'])
def add_post():
conn = get_db()
cur = conn.cursor()
if request.method == "POST":
apost = request.form['posts']
if len(apost) > 140:
abort(400)
else:
cur.execute('INSERT INTO mytable (posts) VALUES (?)', [apost])
conn.commit()
flash('Successfully posted')
return redirect(url_for('root'))


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

body { font-family: sans-serif; background: #eee; }
a, h1, h2 { color: #377ba8; }
h1, h2 { font-family: 'Georgia', serif; margin: 0; }
h1 { border-bottom: 2px solid #eee; }
h2 { font-size: 1.2em; }

.page { margin: 2em auto; width: 35em; border: 5px solid #ccc;
padding: 0.8em; background: white; }
.posts { list-style: none; margin: 0; padding: 0; }
.posts li { margin: 0.8em 1.2em; }
.posts li h2 { margin-left: -1em; }
.add-post { font-size: 0.9em; border-bottom: 1px solid #ccc; }
.add-post dl { font-weight: bold; }
.metanav { text-align: right; font-size: 0.8em; padding: 0.3em;
margin-bottom: 1em; background: #fafafa; }
.flash { background: #cee5F5; padding: 0.5em;
border: 1px solid #aacbe2; }
.error { background: #f0d6d6; padding: 0.5em; }

18 changes: 18 additions & 0 deletions squawker/templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{% extends "layout.html" %}
{% block body %}
<form action="{{ url_for('add_post') }}" method=post class=add-posts>
<dl>
<dt>Posts goes here:
<dd><textarea name=posts maxlength = "140"></textarea>
<dd><input type=submit value=Share>
</dl>
</form>
<ul class=posts>
{% for post in posts %}
<li><h2>posts:</h2><p>{{ post }}</p>
{% else %}
<li><em>Unbelievable. No posts here so far</em>
{% endfor %}
</ul>
{% endblock %}

15 changes: 15 additions & 0 deletions squawker/templates/layout.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<title>squawker</title>
<link rel=stylesheet type=text/css href="{{ url_for('static', filename='style.css') }}">
<div class=page>
<h1>Squawker</h1>
<div class=metanav>
</div>
{% for message in get_flashed_messages() %}
<div class=flash>{{ message }}</div>
{% endfor %}
{% block body %}{% endblock %}
</div>
</html>

5 changes: 5 additions & 0 deletions src/pip-delete-this-directory.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
This file is placed here by pip to indicate the source was put
here by pip.

Once this package is successfully installed this source code will be
deleted (unless you remove this file).
1 change: 1 addition & 0 deletions src/splinter
Submodule splinter added at ba3afc