-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.py
57 lines (46 loc) · 1.52 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from flask import Flask, render_template
from bson import ObjectId
from utils import *
import json
app = Flask(__name__)
id = []
# returns the UI
@app.route("/")
def hello():
#getting a mongodb connection
db = dbConnection()
#get an existing table
if "tbl_counter" in db.collection_names():
tbl_counter = db.get_collection('tbl_counter')
#get no of likes
result = (tbl_counter.find_one())
return render_template("index.html", count=result['counter'])
#posts the count of likes
@app.route("/like", methods=['POST'])
def postData():
#getting a mongodb connection
db = dbConnection()
#get an existing table
if "tbl_counter" in db.collection_names():
tbl_counter = db.get_collection('tbl_counter')
#update vale of likes to current no. of like + 1
tbl_counter.update(tbl_counter.find_one(), {'$inc': {'counter':1}}, upsert=False)
#get no of likes
result = (tbl_counter.find_one())
return str(result['counter'])
#resets like to 0
@app.route("/reset", methods=['POST'])
def resetData():
#getting a mongodb connection
db = dbConnection()
#get an existing table
if "tbl_counter" in db.collection_names():
tbl_counter = db.get_collection('tbl_counter')
#update vale of likes to 0
tbl_counter.update(tbl_counter.find_one(), {'$set': {'counter': 0}}, upsert=False)
#get no of likes
result = (tbl_counter.find_one())
return str(result['counter'])
if __name__ == "__main__":
setupDB()
app.run(debug=True,host='0.0.0.0')