From ce2e844aa981d18cfa1be9869811a8bb06bf8f9c Mon Sep 17 00:00:00 2001 From: roycboyc Date: Tue, 25 Oct 2016 00:07:11 -0400 Subject: [PATCH 01/10] Add files via upload --- index.html | 46 +++++++++++++++++++++++++++++++++++++++++++ schema.sql | 7 +++++++ server.py | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 111 insertions(+) create mode 100644 index.html create mode 100644 schema.sql create mode 100644 server.py diff --git a/index.html b/index.html new file mode 100644 index 0000000..842c296 --- /dev/null +++ b/index.html @@ -0,0 +1,46 @@ + + + + Squawker Nation + + + + +
+
+ +
+ + +
+ +
+ +
+ +
+ +
+ +
+ + +
+ + + {% for sqawk in sqawks %} +
+ {{squawk[2]}} + {{squawk[1]}} +
+ {% endfor %} +
+ + + + \ No newline at end of file diff --git a/schema.sql b/schema.sql new file mode 100644 index 0000000..5b8bf0f --- /dev/null +++ b/schema.sql @@ -0,0 +1,7 @@ +DROP TABLE IF EXISTS squawks; +CREATE TABLE sqawks ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + squawk VARCHAR(140) DEFAULT NULL, + ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP +); + diff --git a/server.py b/server.py new file mode 100644 index 0000000..2994280 --- /dev/null +++ b/server.py @@ -0,0 +1,58 @@ + +from flask import Flask, g, request, render_template +import sqlite3 + + +# -- leave these lines intact -- +app = Flask(__name__) + + +def get_db(): + if not hasattr(g, 'sqlite_db'): + db_name = app.config.get('DATABASE', 'squawker.db') + g.sqlite_db = sqlite3.connect(db_name) + + return g.sqlite_db + + +def init_db(): + with app.app_context(): + db = get_db() + with app.open_resource('schema.sql', mode='r') as f: + db.cursor().executescript(f.read()) + db.commit() + + +@app.cli.command('initdb') +def initdb_command(): + """Creates the database tables.""" + init_db() + print('Initialized the database.') + + +@app.teardown_appcontext +def close_connection(exception): + db = getattr(g, 'sqlite_db', None) + if db is not None: + db.close() +# ------------------------------ + + +@app.route('/', methods=["POST"]) +def root(): + conn = get_db() + cur=conn.cursor() + if request.method == "POST": + newS=request.form.get("content") + if len(newS)<140: + toExecute="INSERT INTO squawks (squawk) VALUES (?)" + cur.execute(toExecute, [newS]) + cur.commit() + sel="SELECT squawk FROM squawks ORDER BY id DESC" + cur.execute(sel) + all=cur.fetchall() + cur.close() + return render_template("index.html", squawks=allS) + +if __name__ == '__main__': + app.run() From d0520f515bf4ea800840efcb47a53eca932013a1 Mon Sep 17 00:00:00 2001 From: roycboyc Date: Tue, 25 Oct 2016 00:41:22 -0400 Subject: [PATCH 02/10] it's so quiet this time of night --- index.html | 23 +++++++++++++++++++---- server.py | 19 ++++++++++--------- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/index.html b/index.html index 842c296..4dc1478 100644 --- a/index.html +++ b/index.html @@ -7,6 +7,21 @@ margin:auto; background-color: #D3D3D3; text-decoration-color: blue; + } + + label + { + font-family:fantasy; + display: block; + width: 156px; + cursor: pointer; + padding-right: 6px; + padding-bottom: 1px; + } + form { + + margin: auto; + } @@ -32,12 +47,12 @@
- - {% for sqawk in sqawks %} -
+ +
    + {% for squawk in squawks %} {{squawk[2]}} {{squawk[1]}} -
+ {% endfor %}
diff --git a/server.py b/server.py index 2994280..9738bb4 100644 --- a/server.py +++ b/server.py @@ -1,7 +1,6 @@ - from flask import Flask, g, request, render_template import sqlite3 - +import datetime # -- leave these lines intact -- app = Flask(__name__) @@ -43,14 +42,16 @@ def root(): conn = get_db() cur=conn.cursor() if request.method == "POST": - newS=request.form.get("content") - if len(newS)<140: - toExecute="INSERT INTO squawks (squawk) VALUES (?)" - cur.execute(toExecute, [newS]) - cur.commit() - sel="SELECT squawk FROM squawks ORDER BY id DESC" + newS=request.form.get("content") + if len(newS)<=140: + toExecute="INSERT INTO squawks (squawk, ts) VALUES (?, ?)" + cur.execute(toExecute, [newS, newTS]) + cur.commit() + else: + abort(400) + sel="SELECT squawk FROM squawks ORDER BY ts DESC" cur.execute(sel) - all=cur.fetchall() + allS=cur.fetchall() cur.close() return render_template("index.html", squawks=allS) From a68e7c5c355853702a7e0ee679422b75c93b0214 Mon Sep 17 00:00:00 2001 From: roycboyc Date: Wed, 26 Oct 2016 11:21:33 -0400 Subject: [PATCH 03/10] here we go again --- index.html | 26 ++++++++++++++------------ schema.sql | 2 +- server.py | 20 ++++++++++---------- 3 files changed, 25 insertions(+), 23 deletions(-) diff --git a/index.html b/index.html index 4dc1478..f3e4463 100644 --- a/index.html +++ b/index.html @@ -9,11 +9,11 @@ text-decoration-color: blue; } - label + h2 { - font-family:fantasy; + font-family: Helvetica; display: block; - width: 156px; + width: 260px; cursor: pointer; padding-right: 6px; padding-bottom: 1px; @@ -30,8 +30,8 @@
- - + What's happening?
+
@@ -44,16 +44,18 @@
- +
- - + {% block content %} +

Trending on Squawker

    - {% for squawk in squawks %} - {{squawk[2]}} - {{squawk[1]}} + {% for sqk in squawks %} +
      {{ sqk[2] }}
    +
      {{ sqk[1] }}
    + {% else %} +
      Get squawking!
- {% endfor %} + {% endfor %}
diff --git a/schema.sql b/schema.sql index 5b8bf0f..6471ad5 100644 --- a/schema.sql +++ b/schema.sql @@ -1,5 +1,5 @@ DROP TABLE IF EXISTS squawks; -CREATE TABLE sqawks ( +CREATE TABLE squawks ( id INTEGER PRIMARY KEY AUTOINCREMENT, squawk VARCHAR(140) DEFAULT NULL, ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP diff --git a/server.py b/server.py index 9738bb4..397b54d 100644 --- a/server.py +++ b/server.py @@ -1,11 +1,10 @@ -from flask import Flask, g, request, render_template +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') @@ -36,24 +35,25 @@ def close_connection(exception): db.close() # ------------------------------ - -@app.route('/', methods=["POST"]) +@app.route('/', methods = ["GET", "POST"]) def root(): conn = get_db() - cur=conn.cursor() + cur = conn.cursor() if request.method == "POST": - newS=request.form.get("content") - if len(newS)<=140: - toExecute="INSERT INTO squawks (squawk, ts) VALUES (?, ?)" + newS = request.form["msg"] + if len(newS) <= 140: + newTS = datetime.datetime.now() + toExecute = "INSERT INTO squawks (msg, ts) VALUES (?, ?)" cur.execute(toExecute, [newS, newTS]) cur.commit() else: abort(400) - sel="SELECT squawk FROM squawks ORDER BY ts DESC" + sel = "SELECT * FROM squawks ORDER BY ts DESC" cur.execute(sel) - allS=cur.fetchall() + allS = cur.fetchall() cur.close() return render_template("index.html", squawks=allS) if __name__ == '__main__': + app.debug = True app.run() From 2a5146f2cc11c3ff1577d954ee5276603486544b Mon Sep 17 00:00:00 2001 From: roycboyc Date: Wed, 26 Oct 2016 11:23:56 -0400 Subject: [PATCH 04/10] againnn --- server.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server.py b/server.py index 397b54d..53a10fb 100644 --- a/server.py +++ b/server.py @@ -52,7 +52,7 @@ def root(): cur.execute(sel) allS = cur.fetchall() cur.close() - return render_template("index.html", squawks=allS) + return render_template("index.html", squawks = allS) if __name__ == '__main__': app.debug = True From ef4078379d8a8726dc2c90c964b7fac2f53da119 Mon Sep 17 00:00:00 2001 From: roycboyc Date: Wed, 26 Oct 2016 11:34:35 -0400 Subject: [PATCH 05/10] fixed server.py --- server.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/server.py b/server.py index 53a10fb..ea60edc 100644 --- a/server.py +++ b/server.py @@ -42,17 +42,18 @@ def root(): if request.method == "POST": newS = request.form["msg"] if len(newS) <= 140: - newTS = datetime.datetime.now() - toExecute = "INSERT INTO squawks (msg, ts) VALUES (?, ?)" - cur.execute(toExecute, [newS, newTS]) - cur.commit() + toExecute="INSERT INTO squawks (squawk) VALUES (?)" + cur.execute(toExecute, [newS]) + conn.commit() else: abort(400) + + sel = "SELECT * FROM squawks ORDER BY ts DESC" cur.execute(sel) allS = cur.fetchall() cur.close() - return render_template("index.html", squawks = allS) + return render_template("index.html", squawks=allS) if __name__ == '__main__': app.debug = True From 32472e5812dd16ba8921a4a5ef63a3a6864d32ab Mon Sep 17 00:00:00 2001 From: roycboyc Date: Wed, 26 Oct 2016 11:43:21 -0400 Subject: [PATCH 06/10] 11:43 --- index.html | 3 +-- server.py | 13 +++++-------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/index.html b/index.html index f3e4463..4d58590 100644 --- a/index.html +++ b/index.html @@ -50,8 +50,7 @@

Trending on Squawker

    {% for sqk in squawks %} -
      {{ sqk[2] }}
    -
      {{ sqk[1] }}
    +
      {{ sqk[0] }}
    {% else %}
      Get squawking!
diff --git a/server.py b/server.py index ea60edc..4c41dfb 100644 --- a/server.py +++ b/server.py @@ -42,17 +42,14 @@ def root(): if request.method == "POST": newS = request.form["msg"] if len(newS) <= 140: - toExecute="INSERT INTO squawks (squawk) VALUES (?)" - cur.execute(toExecute, [newS]) + cur.execute("INSERT INTO squawks (squawk) VALUES (?)", [newS]) conn.commit() else: abort(400) - - - sel = "SELECT * FROM squawks ORDER BY ts DESC" - cur.execute(sel) - allS = cur.fetchall() - cur.close() + + 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__': From 28a5692810bb1c3a16dec712c4a94f4d96999630 Mon Sep 17 00:00:00 2001 From: roycboyc Date: Sun, 6 Nov 2016 10:40:29 -0500 Subject: [PATCH 07/10] templates as folder --- templates/index.html | 62 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 templates/index.html diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..83fe10e --- /dev/null +++ b/templates/index.html @@ -0,0 +1,62 @@ + + + + Squawker Nation + + + + +
+ + +
+ What's happening?
+ +
+ +
+ +
+ + + +
+ +
+ +
+
+

Trending on Squawker

+
    + {% for sqk in squawks %} +
      {{ sqk[2] }}
    +
      {{ sqk[1] }}
    + {% else %} +
      Get squawking!
    +
+ {% endfor %} +
+ + + + \ No newline at end of file From 74a38f4ac6916b67b08454ee5461f3461fe8ccd3 Mon Sep 17 00:00:00 2001 From: roycboyc Date: Sun, 6 Nov 2016 10:47:01 -0500 Subject: [PATCH 08/10] squawker / templates --- squawker/__pycache__/__init__.cpython-35.pyc | Bin 0 -> 140 bytes squawker/__pycache__/server.cpython-35.pyc | Bin 0 -> 1955 bytes squawker/schema.sql | 10 ++- squawker/server.py | 25 +++++--- squawker/templates/index.html | 62 +++++++++++++++++++ 5 files changed, 86 insertions(+), 11 deletions(-) create mode 100644 squawker/__pycache__/__init__.cpython-35.pyc create mode 100644 squawker/__pycache__/server.cpython-35.pyc create mode 100644 squawker/templates/index.html diff --git a/squawker/__pycache__/__init__.cpython-35.pyc b/squawker/__pycache__/__init__.cpython-35.pyc new file mode 100644 index 0000000000000000000000000000000000000000..a9947d747debc208e5a26481db875c8d23a776b8 GIT binary patch literal 140 zcmWgR<>fND!56^*1dl-k3@`#24nSPY0whux7=kq!{Z=v*frJsnFH8Nh#Pp)Xyb}H5 z!qUX@?9?LNw4B7^Y~7;#O1Kb$5g(tKmst`YuUAlci^C>2KczG$)edB2F%UBV0Fgl= AMF0Q* literal 0 HcmV?d00001 diff --git a/squawker/__pycache__/server.cpython-35.pyc b/squawker/__pycache__/server.cpython-35.pyc new file mode 100644 index 0000000000000000000000000000000000000000..9a19a094e1b77ee08ecb4f0ce1956fce9820d2e8 GIT binary patch literal 1955 zcmZ8hOK%%D5FYMBE6I}O*m0T^L9&M;v5Lky6lgDfIgU~oP36>5+jK9Bl}O7g??Wc3 z#1ZV1dn}Lw{Rh4E_w+`fhoYzag`7IWwH>z$EkzDzmcwtp`EIn^%|E}n`}{W_;2*g1 z;2OTdSN)9x#~*_XAZHLU$Q_6r$X$qB$UTTW$bE=>VC3gOR)eT!V{jfo6o6nL>Trg^ z4d5dGb2&25nK)vfb?f$B?B9Xub-E4#>ZNuTfNN$LV!A15Db1LHGI_ye4#g<3Gs~b!gbc1X3K$ zh0>-YMZtxPwa8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ening?
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+
+

Trending on Squawker

+
    + {% for sqk in squawks %} +
      {{ sqk[2] }}
    +
      {{ sqk[1] }}
    + {% else %} +
      Get squawking!
    +
+ {% endfor %} +
+ + + + \ No newline at end of file From 7b8ab5c36f49577bc1002e9b5851a18c8a474bc0 Mon Sep 17 00:00:00 2001 From: roycboyc Date: Sun, 6 Nov 2016 10:50:58 -0500 Subject: [PATCH 09/10] Delete server.py --- server.py | 57 ------------------------------------------------------- 1 file changed, 57 deletions(-) delete mode 100644 server.py diff --git a/server.py b/server.py deleted file mode 100644 index 4c41dfb..0000000 --- a/server.py +++ /dev/null @@ -1,57 +0,0 @@ -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') - g.sqlite_db = sqlite3.connect(db_name) - - return g.sqlite_db - - -def init_db(): - with app.app_context(): - db = get_db() - with app.open_resource('schema.sql', mode='r') as f: - db.cursor().executescript(f.read()) - db.commit() - - -@app.cli.command('initdb') -def initdb_command(): - """Creates the database tables.""" - init_db() - print('Initialized the database.') - - -@app.teardown_appcontext -def close_connection(exception): - db = getattr(g, 'sqlite_db', None) - if db is not None: - db.close() -# ------------------------------ - -@app.route('/', methods = ["GET", "POST"]) -def root(): - conn = get_db() - 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() From 058ce5839193854682a17441f54a4ad9a251cc4b Mon Sep 17 00:00:00 2001 From: roycboyc Date: Tue, 15 Nov 2016 19:54:11 -0500 Subject: [PATCH 10/10] Update server.py --- squawker/server.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/squawker/server.py b/squawker/server.py index 4c41dfb..ca23bfe 100644 --- a/squawker/server.py +++ b/squawker/server.py @@ -33,7 +33,7 @@ def close_connection(exception): db = getattr(g, 'sqlite_db', None) if db is not None: db.close() -# ------------------------------ +# ------------------------------- @app.route('/', methods = ["GET", "POST"]) def root():