diff --git a/.gitignore b/.gitignore index bee8a64..351f747 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ __pycache__ +instance diff --git a/requirements.txt b/requirements.txt index 9ef3eae..4b15b1c 100755 --- a/requirements.txt +++ b/requirements.txt @@ -4,5 +4,5 @@ python-dotenv==1.0.0 aiohttp>=3.7.4,<4 audioop-lts; python_version>='3.13' -flask==2.3.2 -#flask-sqlalchemy==3.0.3 \ No newline at end of file +flask>=2.3.2 +flask-sqlalchemy>=3.0.3 \ No newline at end of file diff --git a/schema.sql b/schema.sql new file mode 100644 index 0000000..833224d --- /dev/null +++ b/schema.sql @@ -0,0 +1,6 @@ +CREATE TABLE IF NOT EXISTS `message` ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + `enable` BOOLEAN NOT NULL DEFAULT FALSE, + `text` VARCHAR(256) NULL, + periodicity INTEGER NULL +); \ No newline at end of file diff --git a/webapp/__init__.py b/webapp/__init__.py index ae4a1f4..ac0d2c9 100644 --- a/webapp/__init__.py +++ b/webapp/__init__.py @@ -1,11 +1,15 @@ from flask import Flask -# from flask_sqlalchemy import SQLAlchemy -# import os - -# file_path = os.path.abspath(os.getcwd())+"/todo.db" +from flask_sqlalchemy import SQLAlchemy +from sqlalchemy.sql import text webapp = Flask(__name__) -# app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///'+file_path -# db = SQLAlchemy(app) +webapp.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///database.db' +db = SQLAlchemy(webapp) -from webapp import routes \ No newline at end of file +from webapp import routes + +with webapp.app_context(): + with open('schema.sql', 'r') as f: + sql_script = f.read() + db.session.execute(text(sql_script)) + db.session.commit() diff --git a/webapp/models.py b/webapp/models.py new file mode 100644 index 0000000..b74a6c0 --- /dev/null +++ b/webapp/models.py @@ -0,0 +1,8 @@ +from webapp import db + +class Message(db.Model): + id = db.Column(db.Integer, primary_key=True) + enable = db.Column(db.Boolean, default=False) + text = db.Column(db.String(200)) + # en seconde + periodicity = db.Column(db.Integer) diff --git a/webapp/routes.py b/webapp/routes.py index a26525d..2ff1dcb 100644 --- a/webapp/routes.py +++ b/webapp/routes.py @@ -1,6 +1,10 @@ from flask import Flask, render_template -from webapp import webapp +from webapp import webapp, db +from webapp.models import Message @webapp.route("/") def index(): + # message = Message(text="bla bla", periodicity = 3600) + # db.session.add(message) + # db.session.commit() return render_template("index.html") diff --git a/webapp/templates/template.html b/webapp/templates/template.html index cf5a6d5..02673e2 100644 --- a/webapp/templates/template.html +++ b/webapp/templates/template.html @@ -21,6 +21,7 @@