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
62 changes: 62 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<!DOCTYPE html>
<html>
<head>
<title>Squawker Nation</title>
<style>
body {
margin:auto;
background-color: #D3D3D3;
text-decoration-color: blue;
}

h2
{
font-family: Helvetica;
display: block;
width: 260px;
cursor: pointer;
padding-right: 6px;
padding-bottom: 1px;
}
form {

margin: auto;
}
</style>
</head>

<body>
<div class="postSquawk">
<form action="/" method = "post">

<div>
What's happening? <br>
<textarea name = "msg" id = "msg" maxlength = "140"></textarea>
</div>

<div class="button">
<button type = "submit">Squawk!</button>
</div>

</form>

</div>

<br>
<img src="http://farm9.static.flickr.com/8016/7102983445_59098c4bc3_m.jpg">
<br>
<div class="recieveSquawk">
{% block content %}
<h2>Trending on Squawker</h2>
<ul>
{% for sqk in squawks %}
<ul>{{ sqk[0] }}</ul>
{% else %}
<ul>Get squawking!</ul>
</ul>
{% endfor %}
</div>


</body>
</html>
7 changes: 7 additions & 0 deletions schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
DROP TABLE IF EXISTS squawks;
CREATE TABLE squawks (
id INTEGER PRIMARY KEY AUTOINCREMENT,
squawk VARCHAR(140) DEFAULT NULL,
ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

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.
10 changes: 7 additions & 3 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,
squawk VARCHAR(140) DEFAULT NULL,
ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

27 changes: 18 additions & 9 deletions squawker/server.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from flask import Flask, g
from flask import Flask, g, request, render_template, abort
import sqlite3

import datetime

# -- leave these lines intact --
app = Flask(__name__)


def get_db():
if not hasattr(g, 'sqlite_db'):
db_name = app.config.get('DATABASE', 'squawker.db')
Expand Down Expand Up @@ -34,15 +33,25 @@ def close_connection(exception):
db = getattr(g, 'sqlite_db', None)
if db is not None:
db.close()
# ------------------------------
# -------------------------------


@app.route('/')
@app.route('/', methods = ["GET", "POST"])
def root():
conn = get_db()
# TODO change this
return "Hello World!"

cur = conn.cursor()
if request.method == "POST":
newS = request.form["msg"]
if len(newS) <= 140:
cur.execute("INSERT INTO squawks (squawk) VALUES (?)", [newS])
conn.commit()
else:
abort(400)

sel = cur.execute("SELECT * FROM squawks ORDER BY ts DESC")
allS = sel.fetchall()
conn.close()
return render_template("index.html", squawks=allS)

if __name__ == '__main__':
app.debug = True
app.run()
62 changes: 62 additions & 0 deletions squawker/templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<!DOCTYPE html>
<html>
<head>
<title>Squawker Nation</title>
<style>
body {
margin:auto;
background-color: #D3D3D3;
text-decoration-color: blue;
}

h2
{
font-family: Helvetica;
display: block;
width: 260px;
cursor: pointer;
padding-right: 6px;
padding-bottom: 1px;
}
form {

margin: auto;
}
</style>
</head>

<body>
<div class="postSquawk">
<form action="/" method = "post">

<div>
What's happening? <br>
<textarea name = "msg" id = "msg" maxlength = "140"></textarea>
</div>

<div class="button">
<button type = "submit">Squawk!</button>
</div>

</form>

</div>

<br>
<img src="http://farm9.static.flickr.com/8016/7102983445_59098c4bc3_m.jpg">
<br>
<div class="recieveSquawk">
<h2>Trending on Squawker</h2>
<ul>
{% for sqk in squawks %}
<ul>{{ sqk[2] }}</ul>
<ul>{{ sqk[1] }}</ul>
{% else %}
<ul>Get squawking!</ul>
</ul>
{% endfor %}
</div>


</body>
</html>
62 changes: 62 additions & 0 deletions templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<!DOCTYPE html>
<html>
<head>
<title>Squawker Nation</title>
<style>
body {
margin:auto;
background-color: #D3D3D3;
text-decoration-color: blue;
}

h2
{
font-family: Helvetica;
display: block;
width: 260px;
cursor: pointer;
padding-right: 6px;
padding-bottom: 1px;
}
form {

margin: auto;
}
</style>
</head>

<body>
<div class="postSquawk">
<form action="/" method = "post">

<div>
What's happening? <br>
<textarea name = "msg" id = "msg" maxlength = "140"></textarea>
</div>

<div class="button">
<button type = "submit">Squawk!</button>
</div>

</form>

</div>

<br>
<img src="http://farm9.static.flickr.com/8016/7102983445_59098c4bc3_m.jpg">
<br>
<div class="recieveSquawk">
<h2>Trending on Squawker</h2>
<ul>
{% for sqk in squawks %}
<ul>{{ sqk[2] }}</ul>
<ul>{{ sqk[1] }}</ul>
{% else %}
<ul>Get squawking!</ul>
</ul>
{% endfor %}
</div>


</body>
</html>