This repository has been archived by the owner on Nov 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.py
84 lines (69 loc) · 2.18 KB
/
api.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
import simplejson
from data import *
from flask import Flask, request, jsonify
from flask_cors import CORS, cross_origin
app = Flask(__name__)
CORS(app, resources=r'/api/*', headers='Content-Type')
@app.after_request
def after_request(response):
response.headers.add('Access-Control-Allow-Headers', 'Content-Type,Authorization')
response.headers.add('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS')
response.headers.add('Access-Control-Allow-Credentials', 'true')
return response
@app.route('/',methods=['GET'])
def get_thing():
toReturn = jsonify(get_all_items())
return toReturn
@app.route('/arbitrage' ,methods=['GET'])
@cross_origin()
def get_arbitrage():
response = {"data": get_arb_tab()}
# response = jsonify(response)
return response
@app.route('/item/<string:encodeName>', methods=['GET'])
@cross_origin()
def get_the_item(encodeName):
response = get_item(encodeName)
comments = fetch_comment(encodeName)
detailedData = fetch_detailed_data(encodeName)
recommendations = fetch_recommendations(encodeName)
if len(response) == 0:
return {"found": False}
else:
return {
"found": True,
"data": response,
"comments": comments,
"statistics": detailedData,
"recommendations": recommendations,
}
@app.route('/item/rate', methods=['POST'])
@cross_origin()
def change_like():
data = request.json
status = update_like_num(data['ItemName'],data['Like'])
if (status == False):
return 'Failed'
else:
return 'Success'
@app.route('/item/comments/postComment', methods=['POST'])
@cross_origin()
def post_comment():
data = request.json
status = write_comment(data['ItemName'],data['Body'],data['CreatedAt'])
if (status == False):
return 'Failed'
else:
return 'Success'
@app.route('/item/comments/deleteComment', methods=['POST'])
@cross_origin()
def delete_comment():
data = request.json
status = erase_comment(data['commentId'])
if (status == False):
return 'Failed'
else:
return 'Success'
# Run Server
if __name__ == '__main__':
app.run(debug=True,ssl_context='adhoc')