-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflask_main.py
104 lines (91 loc) · 4.13 KB
/
flask_main.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import matplotlib
matplotlib.use('Agg')
from flask import Flask, request, send_file
from flask_restx import Resource, Api
from flask_cors import CORS
from database_CRUD import SCACRUD
import os
import json
app = Flask(__name__)
CORS(app)
api = Api(app)
@api.route('/se_data/post/')
class SeDataPost(Resource):
def post(self):
sca_db = SCACRUD()
body_json = request.get_json()
uuid = body_json.get('uuid')
user_name = body_json.get('user_name')
bean_name = body_json.get('bean_name')
sweettaste = body_json.get('sweettaste')
sourtaste = body_json.get('sourtaste')
bittertaste = body_json.get('bittertaste')
saltytaste = body_json.get('saltytaste')
scaproperty = body_json.get('scaproperty')
print(scaproperty)
print(type(scaproperty))
sca_db.insertSCA(uuid=uuid, user_name=user_name,
column='uuid, user_name, bean_name, sweettaste, sourtaste, bittertaste, saltytaste, scaproperty',
data='''\'{uuid}\', \'{user_name}\', \'{bean_name}\', \'{sweettaste}\', \'{sourtaste}\', \'{bittertaste}\', \'{saltytaste}\', \'{scaproperty}\''''.format(
uuid=uuid, user_name=user_name, bean_name=bean_name, sweettaste=sweettaste,
sourtaste=sourtaste, bittertaste=bittertaste, saltytaste=saltytaste,
scaproperty=json.dumps(scaproperty)))
result = sca_db.readDB(schema='public', table='se_table',
column='uuid, table_pk, user_name, bean_name, sweettaste, sourtaste, bittertaste, saltytaste, createat, updatedat',
condition='''uuid=\'{uuid}\' AND user_name=\'{user_name}\''''.format(uuid=uuid,
user_name=user_name))[
0]
return {
'uuid': result[0],
'table_pk': result[1],
'user_name': result[2],
'bean_name': result[3],
'sweettaste': result[4],
'sourtaste': result[5],
'bittertaste': result[6],
'saltytaste': result[7],
'createat': result[8].strftime("%m/%d/%Y, %H:%M:%S"),
'updatedat': result[9].strftime("%m/%d/%Y, %H:%M:%S")
}
@api.route('/se_data/<uuid:data_uuid>/<string:user_name>/')
class SeDataCRUD(Resource):
def get(self, data_uuid, user_name):
data_uuid = str(data_uuid)
sca_db = SCACRUD()
result = sca_db.readDB(schema='public', table='se_table',
column='uuid, table_pk, user_name, bean_name, sweettaste, sourtaste, bittertaste, saltytaste, createat, updatedat',
condition='''uuid=\'{uuid}\' AND user_name=\'{user_name}\''''.format(uuid=data_uuid,
user_name=user_name))[
0]
return {
'uuid': result[0],
'table_pk': result[1],
'user_name': result[2],
'bean_name': result[3],
'sweettaste': result[4],
'sourtaste': result[5],
'bittertaste': result[6],
'saltytaste': result[7],
'createat': result[8].strftime("%m/%d/%Y, %H:%M:%S"),
'updatedat': result[9].strftime("%m/%d/%Y, %H:%M:%S")
}
def put(self, data_uuid, user_name):
data_uuid = str(data_uuid)
sca_db = SCACRUD()
True
def delete(self, data_uuid, user_name):
data_uuid = str(data_uuid)
sca_db = SCACRUD()
True
@api.route('/se_image/<uuid:data_uuid>/<string:user_name>/')
class SeImageCRUD(Resource):
def get(self, data_uuid, user_name):
data_uuid = str(data_uuid)
sca_db = SCACRUD()
slug = user_name + '-' + data_uuid[:8]
sca_db.readSCAImage(user_name=user_name, slug=slug)
file_name = slug + '.png'
if os.path.exists(file_name):
return send_file(file_name, mimetype='image/png')
if __name__ == "__main__":
app.run(debug=True, host='0.0.0.0', port=80)