From 29c1e40205936bc8f55fb5c390551e7693095f1f Mon Sep 17 00:00:00 2001 From: Andrea Fiorencis Date: Thu, 26 Feb 2026 13:48:30 +0100 Subject: [PATCH] Implementata funzione aggiornamento file --- app.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app.py b/app.py index bdcfb4a..bd36cdd 100644 --- a/app.py +++ b/app.py @@ -1,4 +1,5 @@ from flask import Flask, jsonify, request, render_template +import json compiti = [ {"id": 1, "descrizione": "Compito matematica"}, @@ -8,6 +9,10 @@ compiti = [ ] id_counter = 5 +def update_file(): + with open('compiti.json', 'w') as f: + json.dump(compiti, f) + app = Flask(__name__) @app.route("/", methods=["GET"]) @@ -38,6 +43,7 @@ def create_compito(): j["id"] = id_counter id_counter += 1 compiti.append(j) + update_file() return jsonify(j), 201 @app.route("/compiti/", methods=["DELETE"]) @@ -46,6 +52,7 @@ def delete_compito(id): if ciscomerda["id"] == id: compiti.remove(ciscomerda) return jsonify(ciscomerda), 200 + update_file() return jsonify([]), 404 app.run("0.0.0.0")