diff --git a/z2/app.py b/z2/app.py
deleted file mode 100644
index 103d91f..0000000
--- a/z2/app.py
+++ /dev/null
@@ -1,173 +0,0 @@
-from flask import Flask, request, redirect, url_for, render_template_string
-import os
-import psycopg2
-from psycopg2 import pool
-
-app = Flask(__name__)
-
-DB_HOST = os.environ.get('DB_HOST', 'localhost')
-DB_PORT = os.environ.get('DB_PORT', '5432')
-DB_NAME = os.environ.get('DB_NAME', 'postgres')
-DB_USER = os.environ.get('DB_USER', 'postgres')
-DB_PASS = os.environ.get('DB_PASS', 'postgres')
-
-connection_pool = psycopg2.pool.SimpleConnectionPool(
- 1, 10,
- host=DB_HOST,
- port=DB_PORT,
- database=DB_NAME,
- user=DB_USER,
- password=DB_PASS
-)
-
-def init_db():
- conn = connection_pool.getconn()
- try:
- with conn.cursor() as cur:
- cur.execute('''
- CREATE TABLE IF NOT EXISTS shopping_items (
- id SERIAL PRIMARY KEY,
- item TEXT NOT NULL,
- quantity INTEGER DEFAULT 1,
- purchased BOOLEAN DEFAULT FALSE
- );
- ''')
- conn.commit()
- except Exception as e:
- print(f"Erreur lors de l'initialisation de la base de données: {e}")
- conn.rollback()
- finally:
- connection_pool.putconn(conn)
-
-HTML_TEMPLATE = """
-
-
-
- Liste de Courses
-
-
-
-
- Ma Liste de Courses
-
-
-
- Articles à acheter
-
- {% for item in items %}
- {% if not item[3] %}
- -
- {{ item[1] }} ({{ item[2] }})
-
-
-
- {% endif %}
- {% endfor %}
-
-
- Articles achetés
-
- {% for item in items %}
- {% if item[3] %}
- -
- {{ item[1] }} ({{ item[2] }})
-
-
-
- {% endif %}
- {% endfor %}
-
-
-
-"""
-
-@app.route('/')
-def index():
- conn = connection_pool.getconn()
- try:
- with conn.cursor() as cur:
- cur.execute("SELECT id, item, quantity, purchased FROM shopping_items ORDER BY purchased, id")
- items = cur.fetchall()
- except Exception as e:
- print(f"Erreur lors de la récupération des articles: {e}")
- items = []
- finally:
- connection_pool.putconn(conn)
-
- return render_template_string(HTML_TEMPLATE, items=items)
-
-@app.route('/add', methods=['POST'])
-def add_item():
- item = request.form.get('item')
- quantity = request.form.get('quantity', 1, type=int)
-
- conn = connection_pool.getconn()
- try:
- with conn.cursor() as cur:
- cur.execute(
- "INSERT INTO shopping_items (item, quantity) VALUES (%s, %s)",
- (item, quantity)
- )
- conn.commit()
- except Exception as e:
- print(f"Erreur lors de l'ajout d'un article: {e}")
- conn.rollback()
- finally:
- connection_pool.putconn(conn)
-
- return redirect(url_for('index'))
-
-@app.route('/toggle/', methods=['POST'])
-def toggle_item(item_id):
- conn = connection_pool.getconn()
- try:
- with conn.cursor() as cur:
- cur.execute(
- "UPDATE shopping_items SET purchased = NOT purchased WHERE id = %s",
- (item_id,)
- )
- conn.commit()
- except Exception as e:
- print(f"Erreur lors du basculement du statut: {e}")
- conn.rollback()
- finally:
- connection_pool.putconn(conn)
-
- return redirect(url_for('index'))
-
-@app.route('/delete/', methods=['POST'])
-def delete_item(item_id):
- conn = connection_pool.getconn()
- try:
- with conn.cursor() as cur:
- cur.execute("DELETE FROM shopping_items WHERE id = %s", (item_id,))
- conn.commit()
- except Exception as e:
- print(f"Erreur lors de la suppression d'un article: {e}")
- conn.rollback()
- finally:
- connection_pool.putconn(conn)
-
- return redirect(url_for('index'))
-
-with app.app_context():
- try:
- init_db()
- except Exception as e:
- print(f"Impossible d'initialiser la base de données: {e}")
-
-if __name__ == "__main__":
- port = int(os.environ.get("PORT", 5000))
- app.run(host='0.0.0.0', port=port, debug=True)
\ No newline at end of file