Skip to content
This repository has been archived by the owner on May 16, 2021. It is now read-only.

Commit

Permalink
Backend database!!!
Browse files Browse the repository at this point in the history
  • Loading branch information
HeatMint committed Sep 18, 2018
1 parent 12a6844 commit c0dfcb2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/data.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
BEGIN TRANSACTION;
CREATE TABLE IF NOT EXISTS `data` (
`size` TEXT NOT NULL,
`count` INTEGER NOT NULL
);
COMMIT;
23 changes: 20 additions & 3 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,27 @@
from tornado.httpserver import HTTPServer
from tornado.ioloop import IOLoop

import sqlite3

app = Flask(__name__)

selquery = "SELECT size FROM data WHERE size = ?"
oldquery = "UPDATE data SET count = count + 1 WHERE size = ?"
newquery = "INSERT INTO data VALUES (?,?)"


def collect(resolution):
pass
connection = sqlite3.connect("data.db")
cursor = connection.cursor()
c = cursor.execute(selquery,(resolution,))
result = c.fetchall()
if result == []:
print "New stuff!!!"
c = cursor.execute(newquery,(resolution,1,))
else:
print "Old stuff!!!"
c = cursor.execute(oldquery,(resolution,))
connection.commit()


@app.route('/')
Expand All @@ -19,7 +34,8 @@ def index():

@app.route('/api', methods=["POST"])
def process():
print request.form.get("size")
resolution = request.form.get("size")
collect((resolution))
# todo logic here
return redirect("/thanks")

Expand All @@ -34,9 +50,10 @@ def thanks():
return send_file("static/thanks.html")


#develop server
'''app.run(
port=80,
# debug=True
debug=True
)'''

http_server = HTTPServer(WSGIContainer(app))
Expand Down

0 comments on commit c0dfcb2

Please sign in to comment.