Tlapbot/tlapbot/__init__.py

36 lines
947 B
Python
Raw Normal View History

2022-08-30 15:25:21 +02:00
import os
2022-06-08 14:22:58 +02:00
from flask import Flask
2022-08-30 15:25:21 +02:00
from apscheduler.schedulers.background import BackgroundScheduler
from tlapbot.db import get_db
from tlapbot.owncast_helpers import give_points_to_chat
2022-06-08 14:22:58 +02:00
def create_app(test_config=None):
app = Flask(__name__, instance_relative_config=True)
2022-08-22 16:43:56 +02:00
app.config.from_object('tlapbot.default_config')
app.config.from_object('tlapbot.config')
2022-06-08 14:22:58 +02:00
# ensure the instance folder exists
try:
os.makedirs(app.instance_path)
except OSError:
pass
from . import db
2022-08-24 13:47:55 +02:00
from . import owncast_webhooks
app.register_blueprint(owncast_webhooks.bp)
2022-06-08 14:22:58 +02:00
db.init_app(app)
2022-08-30 15:25:21 +02:00
def proxy_job():
with app.app_context():
give_points_to_chat(get_db())
points_giver = BackgroundScheduler()
2022-08-30 15:32:17 +02:00
points_giver.add_job(proxy_job, 'interval', seconds=10) # change to 10 minutes out of testing
2022-08-30 15:25:21 +02:00
points_giver.start()
2022-06-08 14:22:58 +02:00
return app
2022-06-08 14:22:58 +02:00
if __name__ == '__main__':
create_app()