-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
100 lines (85 loc) · 2.82 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, abort, send_file, request
from flask_cors import CORS
from infodb import AnimeList
import warnings
from gevent.pywsgi import WSGIServer
warnings.filterwarnings("ignore", message="specific warning message")
app = Flask(__name__)
CORS(app)
app.config['JSON_AS_ASCII'] = False
infos = AnimeList()
@app.route('/partial_name/<string:name>')
def anime_name(name):
if(name is None):
abort(404)
return {
"datas": infos.search_partial_name(name)
}
@app.route('/similar_animes/<int:anime_id>')
def similar_name(anime_id):
current_info = infos.get_info(anime_id)
similar_animes = infos.similar_animes(anime_id)
if((anime_id is None) | (current_info is None) | (similar_animes is None)):
abort(404)
return{
"datas": {
"current_info": current_info,
"similar_animes": similar_animes
}
}
@app.route('/image/<int:anime_id>')
def image(anime_id):
if(anime_id is None): abort(404)
try:
return send_file(f"images/covers/{anime_id}.jpg", mimetype='image/jpg')
except FileNotFoundError:
return 'Image not found', 404
@app.route('/get_info/<int:anime_id>')
def get_info(anime_id):
getInfo = infos.get_info(anime_id)
if((getInfo is None) | (anime_id is None)): abort(404)
return {
"datas": getInfo
}
@app.route('/genre_lists/')
def genre_lists():
return{
"datas": infos.get_genre_list()
}
@app.route('/get_anime_match_genre/<string:genre_selected>')
def get_anime_match_genre(genre_selected):
anime_match_genre = infos.get_anime_match_genre(genre_selected)
if(anime_match_genre is None): abort(404)
return{
"datas": {
"counts": infos.get_genre_counts(genre_selected),
"listanimes" : anime_match_genre
}
}
@app.route('/genre/')
def get_genre_with_page():
genre = request.args.get("name")
page = request.args.get("page")
if((genre is None) | (page is None) | (page.isdigit() is not True) | (infos.is_genre_list_names(genre) is not True)): abort(404)
page_animes = infos.get_genre_with_page(genre, int(page))
if(page_animes is None): abort(404)
return{
"datas": page_animes
}
@app.route('/get_genre_counts/<string:genre_selected>')
def get_genre_counts(genre_selected):
if(infos.is_genre_list_names(genre_selected) is False): abort(404)
return{
"datas": infos.get_genre_counts(genre_selected)
}
@app.route('/get_anime_2023_with_page/')
def get_anime_2023_with_page():
page = request.args.get("page")
if((page is None) | (page.isdigit() is not True)): abort(404)
return{
"datas": infos.get_anime_2023_with_page(int(page))
}
if __name__ == "__main__":
# app.run(host="0.0.0.0", port=5000)
http_server = WSGIServer(('0.0.0.0', 5000), app)
http_server.serve_forever()