forked from Dweepa/Appetize
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.py
More file actions
38 lines (34 loc) · 1003 Bytes
/
Copy pathapi.py
File metadata and controls
38 lines (34 loc) · 1003 Bytes
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
import requests
from flask import Flask, jsonify, request, render_template
from flask_pymongo import PyMongo
import json
from bson import json_util
import base64
import datetime
from flask_cors import CORS
app = Flask(__name__)
app.config['MONGO_DBNAME'] = 'food'
app.config['MONGO_URI'] = "mongodb://localhost/food"
CORS(app)
mongo = PyMongo(app)
@app.route('/<name>/<message>/<rest>', methods=['POST'])
def insert(name,message,rest):
com = mongo.db.comments
print(list(com.find()))
uid = com.insert({"name":name,"message":message, "restaurant":rest})
print(uid)
req = request.json
print(req,name,message)
docs_list = list(com.find())
output=[]
for i in docs_list:
output.append({i['_id']: [i['name'],i['message']]})
return jsonify({"output": output})
@app.route('/<id>', methods=['DELETE'])
def delete(id):
com = mongo.db.comments
u = com.remove({"_id":id})
print(u)
return "hello"
if __name__ == "__main__":
app.run(debug=True)