import json from flask import render_template, jsonify from app import app from app.config import SCOREBOARD_DATA_FILE from app.games import parse_games @app.route("/") def index(): return render_template("index.html") @app.route("/scoreboard") def get_scoreboard(): try: with open(SCOREBOARD_DATA_FILE, "r") as json_file: scoreboard_data = json.load(json_file) except FileNotFoundError: return jsonify({"error": "Failed to retrieve scoreboard data. File not found."}) except json.JSONDecodeError: return jsonify( {"error": "Failed to retrieve scoreboard data. Invalid JSON format."} ) if scoreboard_data: games = parse_games(scoreboard_data) return jsonify( { "live_games": [g for g in games if g["Game State"] == "LIVE"], "pre_games": [g for g in games if g["Game State"] == "PRE"], "final_games": [g for g in games if g["Game State"] == "FINAL"], } ) else: return jsonify({"error": "Failed to retrieve scoreboard data"})