From 217c7177b16ab30b0394ec1fe84f44fefb478d2c Mon Sep 17 00:00:00 2001 From: Sandro Mani Date: Wed, 13 Dec 2023 13:48:24 +0100 Subject: [PATCH] Update dependencies --- requirements.txt | 15 +++++++-------- src/server.py | 23 ++++++++++++++--------- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/requirements.txt b/requirements.txt index 7f7f3df..867241b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,8 +1,7 @@ -Flask==2.3.2 -Werkzeug==2.3.4 -python-dotenv==1.0.0 -Flask-JWT-Extended==4.4.4 -flask-restx==1.1.0 -psycopg2==2.9.6 -SQLAlchemy==1.4.48 -qwc-services-core==1.3.20 +Flask==3.0.0 +Werkzeug==3.0.1 +Flask-JWT-Extended==4.6.0 +flask-restx==1.3.0 +psycopg2==2.9.9 +SQLAlchemy==2.0.23 +qwc-services-core==1.3.21 diff --git a/src/server.py b/src/server.py index f7e24d0..2563cfb 100644 --- a/src/server.py +++ b/src/server.py @@ -112,7 +112,7 @@ def post(self): attempts = 0 while attempts < 100: try: - configconn.execute(sql, key=hexdigest, data=datastr, date=date, expires=expires) + configconn.execute(sql, {"key": hexdigest, "data": datastr, "date": date, "expires": expires}) break except: pass @@ -126,6 +126,7 @@ def post(self): """.format(table=permalinks_table)) configconn.execute(sql) + configconn.commit() configconn.close() # Return @@ -156,7 +157,7 @@ def get(self): WHERE key = :key AND (expires IS NULL OR expires >= CURRENT_DATE) """.format(table=permalinks_table)) try: - data = json.loads(configconn.execute(sql, key=key).first().data) + data = json.loads(configconn.execute(sql, {"key": key}).mappings().first()["data"]) except: pass return jsonify(data) @@ -178,7 +179,7 @@ def get(self): WHERE username = :user """.format(table=user_permalink_table)) try: - data = json.loads(configconn.execute(sql, user=username).first().data) + data = json.loads(configconn.execute(sql, {"user": username}).mappings().first()["data"]) except: data = {} return jsonify(data) @@ -224,7 +225,8 @@ def post(self): SET data = :data, date = :date """.format(table=user_permalink_table)) - conn.execute(sql, user=username, data=datastr, date=date) + conn.execute(sql, {"user": username, "data": datastr, "date": date}) + conn.commit() conn.close() return jsonify({"success": True}) @@ -250,7 +252,7 @@ def get(self): """.format(table=user_bookmark_table, sort_order=sort_order)) try: data = [] - result = conn.execute(sql, user=username) + result = conn.execute(sql, {"user": username}).mappings() for row in result: bookmark = {} bookmark['data'] = json.loads(row.data) @@ -310,13 +312,14 @@ def post(self): attempts = 0 while attempts < 100: try: - conn.execute(sql, user=username, data=datastr, key=hexdigest, date=date, description=description) + conn.execute(sql, {"user": username, "data": datastr, "key": hexdigest, "date": date, "description": description}) break except: pass hexdigest = hashlib.sha224((datastr + str(random.random())).encode('utf-8')).hexdigest()[0:9] attempts += 1 + conn.commit() conn.close() return jsonify({"success": attempts < 100}) @@ -337,7 +340,7 @@ def get(self, key): WHERE username = :user and key = :key """.format(table=user_bookmark_table)) try: - data = json.loads(conn.execute(sql, user=username, key=key).first().data) + data = json.loads(conn.execute(sql, {"user": username, "key": key}).mappings().first()["data"]) except: data = {} return jsonify(data) @@ -356,7 +359,8 @@ def delete(self, key): WHERE key = :key and username = :username """.format(table=user_bookmark_table)) - conn.execute(sql, key=key, username=username) + conn.execute(sql, {"key": key, "username": username}) + conn.commit() conn.close() return jsonify({"success": True}) @@ -402,7 +406,8 @@ def put(self, key): WHERE username = :user and key = :key """.format(table=user_bookmark_table)) - conn.execute(sql, user=username, data=datastr, key=key, date=date, description=description) + conn.execute(sql, {"user": username, "data": datastr, "key": key, "date": date, "description": description}) + conn.commit() conn.close() return jsonify({"success": True})