-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
48 lines (40 loc) · 1.31 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
from flask import Flask
from flask import request, redirect, url_for, render_template, jsonify
from pymongo import MongoClient, errors
from bson.json_util import dumps
import json
app = Flask(__name__)
client = MongoClient('mongodb://localhost:27017/')
db = client.exam_surveillance
try:
x = dumps(db.statss.find_one())
print("\n * Database connection successfull\n")
except:
print("\n -> Database connection failed !!\n")
@app.route('/')
def index():
return "<h1>INDEX PAGE</h1>"
@app.route('/surveillance', methods=['GET', 'POST', 'PUT'])
def surveillance():
if request.method == 'GET':
dataa = dumps(db.statss.find())
dataa = json.loads(dataa)
return render_template('index.html', value=dataa)
if request.method == 'POST':
# new_record = {
# "name": "rohan",
# "moved": 233,
# "talked": 12
# }
# print(request.data)
new_record = request.json
foo = db.statss.insert_one(new_record).inserted_id
return "inserted"
if request.method == 'PUT':
mod = dict(request.json)
key = {"name": mod["name"]}
mod.pop("name")
foo = db.statss.update_one(key, {"$set": mod})
return "updated"
if __name__ == '__main__':
app.run(host='127.0.0.1', port=5000, debug=True)