This repository has been archived by the owner on Aug 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
81 lines (69 loc) · 2.29 KB
/
main.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
from flask_apispec.extension import FlaskApiSpec
from flask import Flask, request, render_template, json
from flask_migrate import Migrate
from flask_jwt_extended import JWTManager
from flask_cors import CORS
import config.default as conf
from apihelp import apih
from models import *
from schema import *
from jwtprovider import jwtProviders
from vtubers import *
from users import *
from filestorage import *
from exceptions import flask_exceptions
import random
apli = Flask(__name__) # Flask App
apli.config.from_object(conf) # Flask Config
db.init_app(apli) # SQLAlchemy init
ma.init_app(apli) # Marshmallow init
vtapi.init_app(apli)
userapi.init_app(apli)
fileapi.init_app(apli)
mi = Migrate(apli, db) # Migrate init
cors = CORS(apli) # CORS method init
jwt = JWTManager(apli) # JSON Web Token method init
docs = FlaskApiSpec(apli) # Flask APISPEC Init for documentation
jwtProviders(jwt) # Define JWT Exceptions
flask_exceptions(apli) # Define Flask Exceptions
docs.register(ListVTubers)
docs.register(ListSongs)
docs.register(GetVTuber)
docs.register(RandomVTuber)
docs.register(GetSong)
docs.register(FindVTuber)
# Flask common routes and routines
@apli.route("/v1")
def ahelp():
accept = request.headers.get('Accept')
if accept and 'text/html' in accept:
return '<h1>Helper</h1>'
return apih, 200
@apli.route("/docs")
def docs():
return render_template("docs.html")
@apli.route("/faqs")
def frequest():
return render_template("faqs.html")
@apli.route("/support")
def support():
return render_template("support.html")
@apli.route("/")
def index():
totalvt = 0
totalali = 0
totalsocial = 0
vtubers = VTuber.query.all()
vtdata = vtuber_schema.dump(vtubers, many=True)
for vt in vtdata:
for aliase in vt["aliases"]:
totalali += 1
for socialn in vt["social"]:
totalsocial += 1
totalvt += 1
rnddata = [] # List to store six vtubers randomly
for i in range(0, 6):
rnddata.append(vtdata.pop(vtdata.index(random.choice(vtdata))))
return render_template("index.html", vtuber=rnddata, total_vtubers=totalvt, total_aliases=totalali, total_social=totalsocial)
if __name__ == '__main__':
apli.run(debug=False)