-
Notifications
You must be signed in to change notification settings - Fork 0
/
dashboard.py
78 lines (54 loc) · 1.94 KB
/
dashboard.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
#!/usr/bin/python3.6
# -*- coding: utf-8 -*-
from gevent import monkey
monkey.patch_all()
import os
from flask import Flask, Response, render_template, Markup, request, redirect
from flask_socketio import SocketIO
import traceback
import bro_utils
from ark_manager import *
from dbo import *
from jinja_filters import html_line_breaks
from configuration import version
realPath = os.path.dirname(os.path.realpath(__file__))
rp = realPath
app = Flask(__name__)
app.config['SECRET_KEY'] = 'kdFJDLGh@#@$@$e502983tuj#$g324'
socketio = SocketIO(app, async_mode='gevent')
app.jinja_env.filters['html_line_breaks'] = html_line_breaks
# app.jinja_env.globals.update()
# app.jinja_env.filters['bbcode'] = utils.render_bbcode
@app.context_processor
def inject_global_variables():
return dict(
GetData=GetData(),
getdata=getdata,
n_to_br=html_line_breaks,
server=server,
version=version
)
def add_background_task(task, interval):
def tsk():
while True:
try:
log.debug(f"Running background task {task.__name__}...")
task()
log.debug(f"Completed background task {task.__name__}!")
except Exception as e:
log.error(f"Can't run background task '{task.__name__}': {e}", exc_info=True)
socketio.sleep(interval)
socketio.start_background_task(tsk)
if __name__ == '__main__':
from background_tasks import patreon_payout, log_chat_gamelog_ordered
add_background_task(log_chat_gamelog_ordered, 10)
# add_background_task(patreon_payout, 3600)
from dashboard_views import app as dashboard_views
from dashboard_api import app as api
app.register_blueprint(dashboard_views)
app.register_blueprint(api)
try:
log.info("Dashboard starting at port 1117...")
socketio.run(app, debug=False, host='0.0.0.0', port=1117)
except:
log.error("Unable to start", exc_info=True)