-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
100 lines (84 loc) · 2.75 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
from flask import Flask, request, jsonify
from scrapper.home import home
from scrapper.top_novel import get_top_novel
from scrapper.novel_info import get_novel_info
from scrapper.novel_chapters_list import get_novel_chapters_list
from scrapper.nove_chapter_info import get_novel_chapter_info
from utils.utils import novel_ranking_list, main
app = Flask(__name__)
@app.route("/")
def novel_home():
try:
home_content = home()
except:
home_content = "error"
return home_content
@app.route("/novel")
def get_top_novel_list():
novel_time = request.args.get("time")
novel_type = request.args.get("type")
if not novel_time or not novel_type:
return {
"status": "error",
"message": "time and type are required",
"hint": {
"time": (
list(novel_ranking_list.keys())
if novel_ranking_list
else novel_ranking_list.keys()
),
"type": (
list(novel_ranking_list["Monthly"].keys())
if novel_ranking_list
else novel_ranking_list["Monthly"].keys()
),
},
}
try:
novel_content = get_top_novel(novel_ranking_list[novel_time][novel_type])
except Exception as e:
novel_content = f"Error: {str(e)}"
return novel_content
@app.route("/novels/<url>")
def get_novel_info_list(url):
if not url:
return {
"status": "error",
"message": "url is required",
}
full_url = main + "/novels/" + url
try:
novel_content = get_novel_info(full_url)
except Exception as e:
novel_content = f"Error: {str(e)}"
return novel_content
@app.route("/chapters/<url>/<number>")
def get_chapters_list(url, number):
if not url or not number:
return {
"status": "error",
"message": "url and number is required",
"hint": {"url": "/chapters/your_url/your_number"},
}
full_url = main + "/chapters/" + url
try:
novel_content = get_novel_chapters_list(full_url, number)
except Exception as e:
novel_content = f"Error: {str(e)}"
return novel_content
@app.route("/info/<url>/<id>")
def get_chapter_info(url, id):
if not url or not id:
return {
"status": "error",
"message": "url and id is required",
"hint": {"url": "/info/your_url/your_id"},
}
full_url = main + "/" + url + "/" + id
try:
novel_content = get_novel_chapter_info(full_url)
except Exception as e:
novel_content = f"Error: {str(e)}"
return jsonify(novel_content)
if __name__ == "__main__":
app.run(host="0.0.0.0", port=8000)