add user_tasks, use questionary instead of inquirer, refactor main.py

This commit is contained in:
LeonOstrez
2023-07-28 10:24:13 +02:00
parent 33e00aec8a
commit 6bbc0f109c
9 changed files with 199 additions and 110 deletions

View File

@@ -63,7 +63,8 @@ def create_tables():
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (app_id)
REFERENCES apps (app_id)
ON UPDATE CASCADE ON DELETE CASCADE
ON UPDATE CASCADE ON DELETE CASCADE,
UNIQUE (app_id, step)
)
""")
@@ -113,9 +114,14 @@ def save_progress(app_id, step, data):
if isinstance(data, dict):
data = json.dumps(data)
# INSERT the data, but on conflict (if the app_id and step combination already exists) UPDATE the data
insert = sql.SQL(
"INSERT INTO progress_steps (app_id, step, data, completed) VALUES (%s, %s, %s, false)"
"""INSERT INTO progress_steps (app_id, step, data, completed)
VALUES (%s, %s, %s, false)
ON CONFLICT (app_id, step) DO UPDATE
SET data = excluded.data, completed = excluded.completed"""
)
cursor.execute(insert, (app_id, step, data))
conn.commit()
@@ -123,6 +129,7 @@ def save_progress(app_id, step, data):
conn.close()
def get_apps_by_id(app_id):
conn = create_connection()
cursor = conn.cursor()