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
Binary file added squawker.db
Binary file not shown.
Binary file added squawker/.DS_Store
Binary file not shown.
Binary file added squawker/__pycache__/__init__.cpython-35.pyc
Binary file not shown.
Binary file added squawker/__pycache__/server.cpython-35.pyc
Binary file not shown.
8 changes: 6 additions & 2 deletions squawker/schema.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
-- 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,
posts varchar(140),
timestamp datetime default CURRENT_TIMESTAMP
);
37 changes: 33 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,40 @@ def close_connection(exception):
# ------------------------------


@app.route('/')
@app.route('/', methods=['GET', 'POST'])
def root():
error = ""
status = 200
conn = get_db()
# TODO change this
return "Hello World!"
# if click on the post button
if(request.method == "POST"):
# get the text from text area id as post_text
post_text = request.form['post_text']
# if longer than 140c, shoot ERROR 400
if len(post_text) > 140:
error = "Post too long, limit to 140"
status = 400
# insert into the database
else:
c = conn.execute("INSERT INTO squawks (\'posts\') VALUES (\'" + post_text + "\')")
conn.commit()
c = conn.execute("SELECT COUNT(*) FROM squawks", ())
count = c.fetchone()[0]
c.close()
return render_template("index.html", num_squawks=count), status


@app.context_processor
def utility_processor():
def loadSquawks():
conn = get_db()
# sort by DESC time
c = conn.execute("SELECT posts FROM squawks ORDER BY timestamp DESC ", ())
squawks = c.fetchall()
c.close()
slen = len(squawks)
return squawks
return dict(loadSquawks=loadSquawks)


if __name__ == '__main__':
Expand Down
Binary file added squawker/templates/.DS_Store
Binary file not shown.
34 changes: 34 additions & 0 deletions squawker/templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Squawker</title>
</head>
<body>
<!-- Form to post a squawk -->
<form action="/" method="post">
<div>
<label for="msg">Type in your post:</label>
<br>
<textarea placeholder="What's going on?" name='post_text' rows='4' cols='80' id="post_text" maxlength="140"></textarea>
</div>
<div class="button">
<button type="submit">Post</button>
</div>
</form>
<!-- List of sqawks -->
<div id="squawks">
<p>Total Squaks Counts: {{num_squawks}}</p>
<br>
{% for squawk in loadSquawks() %}
<br>
<div>{{ squawk[0] }}</div>
{% endfor %}

</div>

<br><br>



</body>
</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