49 lines
1.1 KiB
Python
49 lines
1.1 KiB
Python
from flask import Flask, render_template, request, jsonify
|
|
import json
|
|
import os
|
|
|
|
app = Flask(__name__)
|
|
DATA_FILE = 'attendance_data.json'
|
|
|
|
# Default player names
|
|
DEFAULT_PLAYERS = [
|
|
"Alice", "Bob", "Charlie", "David", "Eve", "Frank", "Grace", "Hannah"
|
|
]
|
|
DEFAULT_GUEST = "Guest"
|
|
|
|
def load_data():
|
|
if not os.path.exists(DATA_FILE):
|
|
data = {
|
|
"players": DEFAULT_PLAYERS,
|
|
"guest": DEFAULT_GUEST,
|
|
"dates": [],
|
|
"attendance": {}
|
|
}
|
|
with open(DATA_FILE, 'w') as f:
|
|
json.dump(data, f)
|
|
with open(DATA_FILE, 'r') as f:
|
|
return json.load(f)
|
|
|
|
def save_data(data):
|
|
with open(DATA_FILE, 'w') as f:
|
|
json.dump(data, f, indent=2)
|
|
|
|
@app.route('/')
|
|
def index():
|
|
return render_template('index.html')
|
|
|
|
@app.route('/api/data', methods=['GET'])
|
|
def get_data():
|
|
return jsonify(load_data())
|
|
|
|
@app.route('/api/data', methods=['POST'])
|
|
def update_data():
|
|
data = request.json
|
|
save_data(data)
|
|
return jsonify({"status": "success"})
|
|
|
|
if __name__ == '__main__':
|
|
import os
|
|
port = int(os.environ.get('PORT', 5000))
|
|
app.run(host='0.0.0.0', port=port, debug=False)
|