Added new calculator with embedded simple tournament

This commit is contained in:
2026-06-05 22:48:49 +02:00
parent 3269e05f6a
commit 1ad9534819
6 changed files with 842 additions and 243 deletions
+45
View File
@@ -2569,5 +2569,50 @@ def set_language(language):
'message': f'Unsupported language: {language}'
}), 400
# ── Calculator leaderboard & display settings ────────────────────────────────
CALC_LEADERBOARD_FILE = os.path.join('data', 'calculator_leaderboard.json')
@app.route('/api/calculator/leaderboard', methods=['GET'])
def get_calculator_leaderboard():
try:
if os.path.exists(CALC_LEADERBOARD_FILE):
with open(CALC_LEADERBOARD_FILE, 'r', encoding='utf-8') as f:
return jsonify(json.load(f))
return jsonify([])
except Exception as e:
return jsonify({'status': 'error', 'message': str(e)}), 500
@app.route('/api/calculator/leaderboard', methods=['POST'])
def save_calculator_leaderboard():
try:
data = request.get_json()
os.makedirs('data', exist_ok=True)
with open(CALC_LEADERBOARD_FILE, 'w', encoding='utf-8') as f:
json.dump(data, f, indent=2, ensure_ascii=False)
return jsonify({'status': 'success'})
except Exception as e:
return jsonify({'status': 'error', 'message': str(e)}), 500
@app.route('/api/calculator/display', methods=['GET'])
def get_calculator_display():
try:
settings = load_settings()
return jsonify(settings.get('calc_display', {'enabled': False, 'camera': 1}))
except Exception as e:
return jsonify({'status': 'error', 'message': str(e)}), 500
@app.route('/api/calculator/display', methods=['POST'])
def save_calculator_display():
try:
data = request.get_json()
settings = load_settings()
settings['calc_display'] = {'enabled': bool(data.get('enabled')), 'camera': int(data.get('camera', 1))}
save_settings(settings)
return jsonify({'status': 'success'})
except Exception as e:
return jsonify({'status': 'error', 'message': str(e)}), 500
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000, debug=True)