-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
58 lines (46 loc) · 1.46 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
54
55
56
57
58
import os
from os.path import join, dirname
from dotenv import load_dotenv
from flask import Flask, render_template, request, jsonify
from pymongo import MongoClient
dotenv_path = join(dirname(__file__), '.env')
load_dotenv(dotenv_path)
MONGODB_URI = os.environ.get("MONGODB_URI")
DB_NAME = os.environ.get("DB_NAME")
client = MongoClient(MONGODB_URI)
db = client[DB_NAME]
app = Flask(__name__)
@app.route('/')
def home():
return render_template('index.html')
@app.route("/bucket", methods=["POST"])
def bucket_post():
bucket_receive = request.form['bucket_give']
count = db.bucket.count_documents({})
num = count + 1
doc = {
'num': num,
'bucket': bucket_receive,
'done': 0
}
db.bucket.insert_one(doc)
return jsonify({'msg': 'data saved!'})
@app.route("/bucket/done", methods=["POST"])
def bucket_done():
num_receive = request.form['num_give']
db.bucket.update_one (
{'num': int(num_receive)},
{'$set': {'done': 1}}
)
return jsonify({'msg': 'Update done!'})
@app.route("/delete", methods=["POST"])
def bucket_delete():
num_receive = request.form["num_give"]
db.bucket.delete_one({'num': int(num_receive)})
return jsonify({'msg': 'Item deleted!'})
@app.route("/bucket", methods=["GET"])
def bucket_get():
buckets_list = list(db.bucket.find({},{'_id':False}))
return jsonify({'buckets':buckets_list})
if __name__ == '__main__':
app.run('0.0.0.0', port=5000, debug=True)