Compare commits

...

2 Commits

Author SHA1 Message Date
b430d944bc Aggiunto file JSON compiti in gitignore 2026-02-27 09:43:25 +01:00
bb6408e816 Implementazione lettura file JSON 2026-02-27 09:43:07 +01:00
2 changed files with 20 additions and 7 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
compiti.json

26
app.py
View File

@@ -1,18 +1,30 @@
from flask import Flask, jsonify, request, render_template
import json
import os
compiti = [
{"id": 1, "descrizione": "Compito matematica"},
{"id": 2, "descrizione": "Consegna TPSIT progetto API REST"},
{"id": 3, "descrizione": "Compito di sistemi"},
{"id": 4, "descrizione": "Compito di italiano"}
]
id_counter = 5
compiti = []
id_counter = 0
def update_file():
with open('compiti.json', 'w') as f:
json.dump(compiti, f)
if os.path.isfile('compiti.json'):
with open('compiti.json', 'r') as f:
compiti = json.load(f)
id_counter = 104
else:
compiti = [
{"id": 1, "descrizione": "Compito matematica"},
{"id": 2, "descrizione": "Consegna TPSIT progetto API REST"},
{"id": 3, "descrizione": "Compito di sistemi"},
{"id": 4, "descrizione": "Compito di italiano"}
]
id_counter = 5
update_file()
app = Flask(__name__)
@app.route("/", methods=["GET"])