42 lines
1.1 KiB
Python
42 lines
1.1 KiB
Python
from flask import Flask, jsonify, render_template, request
|
|
from app import database as db
|
|
|
|
|
|
def create_app():
|
|
app = Flask(__name__, template_folder='../templates')
|
|
|
|
@app.route('/')
|
|
def index():
|
|
total, online = db.get_player_counts()
|
|
return render_template(
|
|
'index.html',
|
|
total=total,
|
|
online=online,
|
|
players=db.get_all_players(),
|
|
logs=db.get_recent_logs(200),
|
|
)
|
|
|
|
@app.route('/api/stats')
|
|
def api_stats():
|
|
total, online = db.get_player_counts()
|
|
return jsonify({'total': total, 'online': online, 'offline': total - online})
|
|
|
|
@app.route('/api/players')
|
|
def api_players():
|
|
return jsonify(db.get_all_players())
|
|
|
|
@app.route('/api/logs')
|
|
def api_logs():
|
|
return jsonify(db.get_recent_logs(100))
|
|
|
|
@app.route('/api/sync', methods=['POST'])
|
|
def api_sync():
|
|
from app.scheduler import poll_yodeck
|
|
try:
|
|
poll_yodeck()
|
|
return jsonify({'ok': True})
|
|
except Exception as exc:
|
|
return jsonify({'ok': False, 'error': str(exc)}), 500
|
|
|
|
return app
|