-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient1.py
More file actions
47 lines (35 loc) · 1.12 KB
/
client1.py
File metadata and controls
47 lines (35 loc) · 1.12 KB
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
from flask import Flask, request, jsonify
from pymongo import MongoClient
from bson.json_util import dumps
from flask_cors import CORS
#connect to database
client = MongoClient('localhost', 27017)
db = client.mydb
app = Flask(__name__) # initialize the flask app
CORS(app)
@app.route('/add_task',methods=['POST'])
def add_task():
data=request.get_json()
db['to-do'].insert_one(data)
return dumps(data)
@app.route('/get_tasks')
def get_all_tasks():
data=list(db['to-do'].find())
return dumps(data)
@app.route('/update_task',methods=['POST'])
def update_task():
task=request.get_json()['task']
name=request.get_json()['name']
myquery = {"task": task,"name":name}
newvalues = {"$set": {'status': 'Done'}}
db['to-do'].update_many(myquery,newvalues)
return "successfully updated"
@app.route('/delete_task',methods=['POST'])
def delete_task():
task=request.get_json()['task']
name=request.get_json()['name']
myquery = {"task": task,"name":name}
db['to-do'].delete_many(myquery)
return "successfully deleted"
if __name__ == "__main__":
app.run(host='0.0.0.0', port=5000)