-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
60 lines (44 loc) · 1.41 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
59
60
from flask import Flask, jsonify, request
import table_api
app = Flask(__name__)
def myQueryFunc(conn_str, table_name, query=None, fields=None):
db = table_api.connect_to_db(conn_str)
table = table_api.connect_to_table(db, table_name)
query_results = list(table_api.query(table, query, fields))
return jsonify({"Query results":query_results})
def myPublishFunc(conn_str, table_name, text_path):
table_api.publish(text_path, conn_str, table_name)
return jsonify({"message":f"Successfully published deployment to table \"{table_name}\"!"})
@app.get("/")
# AKA @app.route(path, methods=["GET"])
def index():
return {"Welcome message":"Welcome to my Flask app!"}
@app.post("/query")
# AKA @app.route(path, methods=["POST"])
def query():
data = None
if(request.is_json):
data = request.json
else:
data = request.form
query = None
fields = None
try:
query = data["query"]
except:
query = None
try:
fields = data["fields"]
except:
fields = None
return myQueryFunc(data["connection_string"], data["table_name"], query, fields)
@app.post("/publish")
def publish_entry():
data = None
if(request.is_json):
data = request.json
else:
data = request.form
return myPublishFunc(data["connection_string"], data["table_name"], data["text_path"])
if(__name__ == "__main__"):
app.run(debug=True)