-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.py
More file actions
65 lines (51 loc) · 1.51 KB
/
Copy pathindex.py
File metadata and controls
65 lines (51 loc) · 1.51 KB
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
""" ----------- Import modules ------------------- """
from flask import Flask, jsonify, request
import utils
app = Flask(__name__)
@app.route("/categories", methods=["GET"])
def get_categories():
rows = utils.get_all("SELECT * from category")
data = []
for r in rows:
data.append({
"id": r[0],
"name": r[1],
"url": r[2]
})
return jsonify({"categories": data})
@app.route("/news", methods=["GET"])
def get_news():
rows = utils.get_all('SELECT * FROM news')
data = []
for r in rows:
data.append({
"id": r[0],
"subject": r[1],
"description": r[2],
"image": r[3],
"original_url": r[4]
})
return jsonify({"news": data})
@app.route("/news/<int:news_id>", methods=["GET"])
def get_news_by_id(news_id):
r = utils.get_news_by_id(news_id)
d = {
"subject": r[0],
"description": r[1],
"image": r[2],
"original_url": r[3],
"categories_name": r[4],
"categories_url": r[5]
}
return jsonify({"product": d})
@app.route("/news/<int:news_id>", methods=["POST"])
def insert_comments(news_id):
if request.form.get("content"):
utils.add_comment(news_id, request.form["content"])
return jsonify({"status": 1, "message:": "Successful"})
return jsonify({"status": -1, "message:": "Need news_id"})
@app.route("/news/add", methods=["POST"])
def insert_news():
pass
if __name__ == "__main__":
app.run()