Spaces:
Runtime error
Runtime error
| 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 | |
| def ratelimit_handler(e): return render_template('ratelimit.html'), 429 | |
| def forbidden_handler(e): return render_template('forbidden.html'), 403 | |
| def notfound_handler(e): return render_template('notfound.html'), 404 | |
| def methodnotallowed_handler(e): return render_template('methodnotallowed.html'), 405 | |
| def internalservererror_handler(e): return render_template('intervalservererror.html'), 500 | |
| def badgateway_handler(e): return render_template('badgateway.html'), 502 | |
| #empty routes | |
| def emptyPath(): return {} | |
| def emptyApiWA(path): return {"status": "error", "error_code": 100, "error_details": "No method like that found"} | |
| #icon | |
| def favicon(): return send_from_directory(os.path.join(app.root_path, 'static'), 'favicon.ico', mimetype='image/vnd.microsoft.icon') | |
| ############### | |
| #SITE ROUTES | |
| def index(): return render_template('index.html') | |
| def systemInfo(): return siteRoutes.systemInfo() | |
| ############### | |
| #YT SOUND API | |
| def search(): return ytApi.search(request) | |
| def getFull(): return ytApi.getFull(request) | |
| def getPreview(): return ytApi.getPreview(request) | |
| ############### | |
| #JOKES API | |
| def getJoke(): return jokes.getJoke(request) | |
| def getJokesSources(): return jokes.getSources(request) | |
| ############### | |
| #HOLIDAYS API (dont wanna document it) | |
| def getHolidays(): return holidays.getHolidays(request) | |
| ############### | |
| #OSU API | |
| def findSong(): return osuApi.findSong(request) | |
| def getBeatmap(): return osuApi.getBeatmap(request) | |
| def getBMPreview(): return osuApi.getPreview(request) | |
| def getBMFull(): return osuApi.getFull(request) | |
| ############## | |
| # ANALYZE DATA API | |
| # deprecated | |
| def sentimentAnalys(): | |
| return {"status": "pass", "predicted_sentiment": "neutral"} | |
| 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", ) |