From d8af0da440758219194e9877f980cda7c66a6707 Mon Sep 17 00:00:00 2001 From: ben Date: Thu, 5 Jan 2023 21:39:33 +0000 Subject: [PATCH 1/4] fixes timestamp --- lnbits/extensions/gerty/crud.py | 6 +++--- lnbits/extensions/gerty/templates/gerty/gerty.html | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lnbits/extensions/gerty/crud.py b/lnbits/extensions/gerty/crud.py index 3229c16f..54ce8e1b 100644 --- a/lnbits/extensions/gerty/crud.py +++ b/lnbits/extensions/gerty/crud.py @@ -117,19 +117,19 @@ async def get_mempool_info(endPoint: str, gerty) -> dict: mempool_id, json.dumps(response.json()), endPoint, - db.timestamp_now, + time.time(), gerty.mempool_endpoint, ), ) return response.json() - if int(time.time()) - row.time > 20: + if int(time.time()) - int(row.time) > 20: async with httpx.AsyncClient() as client: response = await client.get(gerty.mempool_endpoint + url) await db.execute( "UPDATE gerty.mempool SET data = ?, time = ? WHERE endpoint = ? AND mempool_endpoint = ?", ( json.dumps(response.json()), - db.timestamp_now, + time.time(), endPoint, gerty.mempool_endpoint, ), diff --git a/lnbits/extensions/gerty/templates/gerty/gerty.html b/lnbits/extensions/gerty/templates/gerty/gerty.html index 06a29e22..d4342ae0 100644 --- a/lnbits/extensions/gerty/templates/gerty/gerty.html +++ b/lnbits/extensions/gerty/templates/gerty/gerty.html @@ -6,7 +6,7 @@ gertyname }}{% endraw %}{% endblock %}{% block page %} {% raw %} v-if="fun_exchange_market_rate || fun_satoshi_quotes" > Date: Thu, 5 Jan 2023 22:20:10 +0000 Subject: [PATCH 2/4] swapped timestamp type for float, fixes issue --- lnbits/extensions/gerty/crud.py | 2 +- lnbits/extensions/gerty/migrations.py | 51 +++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/lnbits/extensions/gerty/crud.py b/lnbits/extensions/gerty/crud.py index 54ce8e1b..24e8ef25 100644 --- a/lnbits/extensions/gerty/crud.py +++ b/lnbits/extensions/gerty/crud.py @@ -122,7 +122,7 @@ async def get_mempool_info(endPoint: str, gerty) -> dict: ), ) return response.json() - if int(time.time()) - int(row.time) > 20: + if float(time.time()) - row.time > 20: async with httpx.AsyncClient() as client: response = await client.get(gerty.mempool_endpoint + url) await db.execute( diff --git a/lnbits/extensions/gerty/migrations.py b/lnbits/extensions/gerty/migrations.py index 654dfcbf..31d1caec 100644 --- a/lnbits/extensions/gerty/migrations.py +++ b/lnbits/extensions/gerty/migrations.py @@ -1,3 +1,5 @@ +import time + async def m001_initial(db): """ Initial Gertys table. @@ -57,3 +59,52 @@ async def m005_add_gerty_model_col(db): support for Gerty model col """ await db.execute("ALTER TABLE gerty.gertys ADD COLUMN urls TEXT;") + +async def m006_add_gerty_model_col(db): + """ + support for Gerty model col + """ + await db.execute("ALTER TABLE gerty.mempool RENAME TO mempool_old;") + await db.execute("ALTER TABLE gerty.mempool ADD COLUMN time FLOAT;") + +async def m006_add_gerty_model_col(db): + """ + Add UUID ID's to links and migrates existing data + """ + await db.execute("ALTER TABLE gerty.mempool RENAME TO mempool_old") + await db.execute( + f""" + CREATE TABLE gerty.mempool ( + id TEXT PRIMARY KEY, + mempool_endpoint TEXT NOT NULL, + endpoint TEXT NOT NULL, + data TEXT NOT NULL, + time FLOAT + ); + """ + ) + + for row in [ + list(row) for row in await db.fetchall("SELECT * FROM gerty.mempool_old") + ]: + await db.execute( + """ + INSERT INTO gerty.mempool ( + id, + mempool_endpoint, + endpoint, + data, + time + ) + VALUES (?, ?, ?, ?, ?) + """, + ( + row[0], + row[1], + row[2], + row[3], + time.time(), + ), + ) + + await db.execute("DROP TABLE gerty.mempool_old") \ No newline at end of file From 84c4643e1bf12b4712ae896509c936e4e128ccb3 Mon Sep 17 00:00:00 2001 From: ben Date: Thu, 5 Jan 2023 22:21:40 +0000 Subject: [PATCH 3/4] format --- lnbits/extensions/gerty/migrations.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lnbits/extensions/gerty/migrations.py b/lnbits/extensions/gerty/migrations.py index 31d1caec..a7a3243b 100644 --- a/lnbits/extensions/gerty/migrations.py +++ b/lnbits/extensions/gerty/migrations.py @@ -1,5 +1,6 @@ import time + async def m001_initial(db): """ Initial Gertys table. @@ -60,6 +61,7 @@ async def m005_add_gerty_model_col(db): """ await db.execute("ALTER TABLE gerty.gertys ADD COLUMN urls TEXT;") + async def m006_add_gerty_model_col(db): """ support for Gerty model col @@ -67,6 +69,7 @@ async def m006_add_gerty_model_col(db): await db.execute("ALTER TABLE gerty.mempool RENAME TO mempool_old;") await db.execute("ALTER TABLE gerty.mempool ADD COLUMN time FLOAT;") + async def m006_add_gerty_model_col(db): """ Add UUID ID's to links and migrates existing data @@ -107,4 +110,4 @@ async def m006_add_gerty_model_col(db): ), ) - await db.execute("DROP TABLE gerty.mempool_old") \ No newline at end of file + await db.execute("DROP TABLE gerty.mempool_old") From 723c9006e1f9ca2af73eedb1bc072f66d1d614c1 Mon Sep 17 00:00:00 2001 From: ben Date: Thu, 5 Jan 2023 22:27:25 +0000 Subject: [PATCH 4/4] duplicate --- lnbits/extensions/gerty/migrations.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/lnbits/extensions/gerty/migrations.py b/lnbits/extensions/gerty/migrations.py index a7a3243b..afef2cfd 100644 --- a/lnbits/extensions/gerty/migrations.py +++ b/lnbits/extensions/gerty/migrations.py @@ -62,14 +62,6 @@ async def m005_add_gerty_model_col(db): await db.execute("ALTER TABLE gerty.gertys ADD COLUMN urls TEXT;") -async def m006_add_gerty_model_col(db): - """ - support for Gerty model col - """ - await db.execute("ALTER TABLE gerty.mempool RENAME TO mempool_old;") - await db.execute("ALTER TABLE gerty.mempool ADD COLUMN time FLOAT;") - - async def m006_add_gerty_model_col(db): """ Add UUID ID's to links and migrates existing data