This repository has been archived by the owner on May 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 260
/
main.py
41 lines (30 loc) · 1.38 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
import os
from flask import Flask
from flask_mongoengine import MongoEngine
from cache import channelsCache
def create_app(test_config=None):
"""Create and configure an instance of the Flask application."""
app = Flask(__name__, instance_relative_config=True)
if app.config["ENV"] == "production":
app.config.from_object("config.ProductionConfig")
else:
app.config.from_object("config.DevelopmentConfig")
if app.config['SECRET_KEY'] is None:
raise Exception(
"SECRET_KEY can't be None. Try to generate one by command: python -c 'import os; print(os.urandom(16))', and copy the result into configs.py.")
if app.config['OWNER_USER_ID'] is None:
raise Exception(
"OWNER_USER_ID can't be None. It is an integer user_id of your Clubhouse account, you can get it from token json file generated by OpenClubhouse-worker")
@app.route("/alive")
def alive():
return {"alive": True}
db = MongoEngine(app)
channelsCache.init_cache(app.logger)
# apply the blueprints to the app
from handlers import clubhouse
app.register_blueprint(clubhouse.bp)
# in another app, you might define a separate main index here with
# app.route, while giving the blog blueprint a url_prefix, but for
# the tutorial the blog will be the main index
app.add_url_rule("/", endpoint="index")
return app