File size: 3,900 Bytes
66ca64a
 
73fd428
 
66ca64a
367be45
66ca64a
 
28a268c
6fb2ead
3f48fa2
66ca64a
ffb7cb9
66ca64a
367be45
66ca64a
 
505fb43
66ca64a
505fb43
66ca64a
505fb43
398212d
505fb43
dbec2e2
505fb43
dbec2e2
505fb43
66ca64a
 
367be45
 
 
5b1514b
66ca64a
 
367be45
 
 
5b1514b
66ca64a
f02b1de
66ca64a
 
367be45
66ca64a
 
47ca12e
 
 
 
09f5da5
89d38c5
66ca64a
 
 
367be45
66ca64a
367be45
66ca64a
367be45
66ca64a
 
5b1514b
 
 
 
 
 
 
73ee427
 
 
 
 
66ca64a
 
367be45
66ca64a
367be45
66ca64a
367be45
66ca64a
367be45
66ca64a
 
6fb2ead
 
ffb7cb9
367be45
6fb2ead
ffb7cb9
c7dfb4e
367be45
c7dfb4e
ffb7cb9
6fb2ead
69aec0a
 
66ca64a
f0b744f
ffb7cb9
 
09f5da5
f0b744f
 
 
 
 
73fd428
 
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
101
102
103
104
105
106
107
108
109
110
111
import os
from flask import *
from waitress import serve
from paste.translogger import TransLogger

from routes.helpers import configFile
from routes import *

from random import randint

#initing
app = Flask(__name__)
VERSION: str = None
app.config['JSON_AS_ASCII'] = False

#error pages
@app.errorhandler(429)
def ratelimit_handler(e): return render_template('ratelimit.html'), 429
@app.errorhandler(403)
def forbidden_handler(e): return render_template('forbidden.html'), 403
@app.errorhandler(404)
def notfound_handler(e): return render_template('notfound.html'), 404
@app.errorhandler(405)
def methodnotallowed_handler(e): return render_template('methodnotallowed.html'), 405
@app.errorhandler(500)
def internalservererror_handler(e): return render_template('intervalservererror.html'), 500
@app.errorhandler(502)
def badgateway_handler(e): return render_template('badgateway.html'), 502

#empty routes
@app.route('/yt/api/v1', methods=['POST'])
@app.route('/recognize/api/v1', methods=['POST'])
@app.route('/osu/api/v1', methods=['POST'])
@app.route('/jokes/api/v1', methods=['POST'])
def emptyPath(): return {} 

@app.route('/yt/api/v1/<path:path>', methods=['POST'])
@app.route('/recognize/api/v1/<path:path>', methods=['POST'])
@app.route('/osu/api/v1/<path:path>', methods=['POST'])
@app.route('/jokes/api/v1/<path:path>', methods=['POST'])
def emptyApiWA(path):  return {"status": "error", "error_code": 100, "error_details": "No method like that found"}
    
#icon
@app.route('/favicon.ico')

def favicon(): return send_from_directory(os.path.join(app.root_path, 'static'), 'favicon.ico', mimetype='image/vnd.microsoft.icon')

###############
#SITE ROUTES
@app.route('/')
def index(): return render_template('index.html') 
@app.route('/system/api/v1/info', methods=['POST'])
def systemInfo(): return siteRoutes.systemInfo()

###############
#YT SOUND API
@app.route('/yt/api/v1/search', methods=['POST'])
def search(): return ytApi.search(request)
@app.route('/yt/api/v1/get-full', methods=['POST'])
def getFull(): return ytApi.getFull(request)
@app.route('/yt/api/v1/get-preview', methods=['POST'])
def getPreview(): return ytApi.getPreview(request)

###############
#JOKES API
@app.route('/jokes/api/v1/get', methods=['POST'])
def getJoke(): return jokes.getJoke(request)
@app.route('/jokes/api/v1/sources', methods=['POST'])
def getJokesSources(): return jokes.getSources(request)

###############
#HOLIDAYS API (dont wanna document it)
@app.route('/holidays/api/v1/get', methods=['POST'])
def getHolidays(): return holidays.getHolidays(request)

###############
#OSU API
@app.route('/osu/api/v1/find-song', methods=['POST'])
def findSong(): return osuApi.findSong(request)
@app.route('/osu/api/v1/get-beatmap', methods=['POST'])
def getBeatmap(): return osuApi.getBeatmap(request)
@app.route('/osu/api/v1/get-preview', methods=['POST'])
def getBMPreview(): return osuApi.getPreview(request)
@app.route('/osu/api/v1/get-full', methods=['POST'])
def getBMFull(): return osuApi.getFull(request)

##############
# ANALYZE DATA API
# deprecated
@app.route('/analyzeText/api/v1/sentiment', methods=['POST'])
def sentimentAnalys():
    return {"status": "pass", "predicted_sentiment": "neutral"}

@app.route('/analyzeText/api/v1/toxicity', methods=['POST'])
def toxicityAnalys():
    return {"status": "pass", "toxicity": False}

##############
# INIT APP
if __name__ == "__main__":
    config = configFile()
    with open(config['config-path'], "r", encoding="utf-8") as outfile:
        VERSION = config['buildVersion']
    with open(config['openapi-yaml-path'], "r+", encoding="utf-8") as outfile:
        info = outfile.read()
        outfile.seek(0)
        outfile.write(info.replace('$VERSION_VARIABLE$', VERSION))
        outfile.truncate()
    
    # $VERSION_VARIABLE$
    serve(TransLogger(app, setup_console_handler=False), host="0.0.0.0", port=7860, threads=4, ident="FunAPI", )