Files
JKTV-online/web/routes/main.py
T

54 lines
1.7 KiB
Python

from flask import Blueprint, render_template, request, jsonify
from web.database import query_db
from web.config import Config
from web.services.stats_service import StatsService
bp = Blueprint('main', __name__)
@bp.route('/healthz')
def healthz():
try:
for db_name in ('l2', 'l3', 'web'):
query_db(db_name, 'SELECT 1', one=True)
except Exception as exc:
return jsonify({
'status': 'unhealthy',
'error': str(exc),
'brand': Config.BRAND_PRIMARY,
}), 503
return jsonify({
'status': 'ok',
'version': '2.0.0-beta',
'brand': Config.BRAND_PRIMARY,
})
@bp.route('/')
def index():
recent_matches = StatsService.get_recent_matches(limit=5)
daily_counts = StatsService.get_daily_match_counts()
live_matches = StatsService.get_live_matches()
# Convert rows to dict for easier JS usage
heatmap_data = {}
if daily_counts:
for row in daily_counts:
heatmap_data[row['day']] = row['count']
return render_template('home/index.html', recent_matches=recent_matches, heatmap_data=heatmap_data, live_matches=live_matches)
@bp.route('/parse_match', methods=['POST'])
def parse_match():
url = request.form.get('url')
if not url or '5eplay.com' not in url:
return jsonify({'success': False, 'message': 'Invalid 5EPlay URL'}), 400
return jsonify({
'success': False,
'message': (
'URL downloader is not included in this repository. '
'Place iframe_network.json under output_arena/<match_id>/ '
'and run the L1/L2/L3 builders from Admin.'
),
}), 501