import sys from pathlib import Path from datetime import datetime from flask import Flask, render_template # Add scripts directory to path to allow importing from it scripts_dir = Path(__file__).parent / "scripts" sys.path.append(str(scripts_dir)) from attendance import get_members_with_fees app = Flask(__name__) @app.route("/") def index(): # Redirect root to /fees for convenience while there are no other apps return '' @app.route("/fees") def fees(): members, sorted_months = get_members_with_fees() if not members: return "No data." # Filter to adults only for display results = [(name, fees) for name, tier, fees in members if tier == "A"] # Format month labels month_labels = { m: datetime.strptime(m, "%Y-%m").strftime("%b %Y") for m in sorted_months } monthly_totals = {m: 0 for m in sorted_months} formatted_results = [] for name, month_fees in results: row = {"name": name, "months": []} for m in sorted_months: fee, count = month_fees.get(m, (0, 0)) monthly_totals[m] += fee cell = f"{fee} CZK ({count})" if count > 0 else "-" row["months"].append(cell) formatted_results.append(row) return render_template( "fees.html", months=[month_labels[m] for m in sorted_months], results=formatted_results, totals=[f"{monthly_totals[m]} CZK" for m in sorted_months] ) if __name__ == "__main__": app.run(debug=True, host='0.0.0.0', port=5001)