
from flask import Flask, render_template, jsonify, request
import json
import os

app = Flask(__name__)

@app.route('/')
def index():
    return render_template("index.html")

@app.route('/api/metrics')
def metrics():
    with open(os.path.join(os.path.dirname(__file__), "../sample_data/metrics.json")) as f:
        data = json.load(f)
    return jsonify(data)

@app.route('/api/config', methods=['POST'])
def config():
    data = request.json
    with open(os.path.join(os.path.dirname(__file__), "../sample_data/config.json"), "w") as f:
        json.dump(data, f)
    return jsonify({"status": "success", "data": data})

@app.route('/api/config')
def get_config():
    config_path = os.path.join(os.path.dirname(__file__), "../sample_data/config.json")
    if os.path.exists(config_path):
        with open(config_path) as f:
            return jsonify(json.load(f))
    else:
        return jsonify({"language": "en", "chatgpt_key": ""})

if __name__ == "__main__":
    app.run(debug=True)
