-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
47 lines (32 loc) · 1.16 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
import os
from flask import Flask, request
from flask_wtf.csrf import CSRFProtect
import crawler as cra
from renderer import render
app = Flask(__name__, static_folder='website', static_url_path='')
app.config['JSON_AS_ASCII'] = False
app.config['SECRET_KEY'] = os.urandom(24)
csrf = CSRFProtect(app)
csrf.init_app(app)
@app.route('/', methods=['GET'])
def give_html():
return app.send_static_file('index.html')
@app.route('/api/articles/<article_id>/info', methods=['GET'])
def article_info(article_id):
board = request.args.get('board')
return cra.get_article(article_id, board, is_include_content=False)
@app.route('/api/articles/<article_id>', methods=['GET'])
def article_content(article_id):
board = request.args.get('board')
raw_data = cra.get_article(article_id, board, is_include_content=True)
return render(raw_data)
@app.route('/api/articles', methods=['GET'])
def article_ids():
page = request.args.get('page')
board = request.args.get('board')
return cra.get_article_ids(board, page)
@app.route('/api/boards', methods=['GET'])
def get_boards():
return cra.get_popular_boards()
if __name__ == '__main__':
app.run()