-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
57 lines (44 loc) · 1.5 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
from flask import Flask, jsonify
from redis import Redis
import json
app = Flask(__name__)
app.config['JSON_AS_ASCII'] = False
rconn = Redis(host='ec2-3-34-134-147.ap-northeast-2.compute.amazonaws.com', port=6379, db=1,
decode_responses=True)
@app.route('/')
def base_url():
response = dict(code=200, status="OK", message=[])
return jsonify(response)
@app.route('/flat_form_list')
def flat_form_list():
response = dict(code=200, status="OK", message=[])
key = 'flat_form_list'
data = list(rconn.smembers(key))
response['message'] = data
return jsonify(response)
@app.route('/flat_form_list/<flat_form>')
def category_list(flat_form):
response = dict(code=200, status="OK", message=[])
category_lists = list()
flat_form_key = flat_form + ':*'
for key in rconn.keys(flat_form_key):
_, category = key.split(':')
category_lists.append(category)
response['message'] = category_lists
return jsonify(response)
@app.route('/<flat_form>/<category>')
def news(flat_form, category):
response = dict(code=200, status="OK", message=[])
key = flat_form + ':' + category
try:
data = rconn.get(key)
news_json = json.loads(data)
response['message'] = news_json
return jsonify(response)
except Exception as e:
print(e)
response['code'] = 400
response['status'] = 'NOT_VALID_DATA'
return response
if __name__ == "__main__":
app.run(host="0.0.0.0", port="5000", debug=True)