From 8e344ecf4b30b5ddc9734a58e8e1b85efca0929a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?dni=20=E2=9A=A1?= Date: Fri, 30 Dec 2022 09:24:31 +0100 Subject: [PATCH 01/10] gerty mypy fixes --- lnbits/extensions/gerty/__init__.py | 2 - lnbits/extensions/gerty/crud.py | 7 ++- lnbits/extensions/gerty/helpers.py | 93 ++++++++++------------------ lnbits/extensions/gerty/models.py | 1 - lnbits/extensions/gerty/views.py | 6 +- lnbits/extensions/gerty/views_api.py | 33 ++++------ pyproject.toml | 1 - 7 files changed, 49 insertions(+), 94 deletions(-) diff --git a/lnbits/extensions/gerty/__init__.py b/lnbits/extensions/gerty/__init__.py index bd353c78e..5b24718ac 100644 --- a/lnbits/extensions/gerty/__init__.py +++ b/lnbits/extensions/gerty/__init__.py @@ -5,11 +5,9 @@ from fastapi.staticfiles import StaticFiles from lnbits.db import Database from lnbits.helpers import template_renderer -from lnbits.tasks import catch_everything_and_restart db = Database("ext_gerty") - gerty_static_files = [ { "path": "/gerty/static", diff --git a/lnbits/extensions/gerty/crud.py b/lnbits/extensions/gerty/crud.py index 1164b6ee4..3012eeaef 100644 --- a/lnbits/extensions/gerty/crud.py +++ b/lnbits/extensions/gerty/crud.py @@ -55,7 +55,10 @@ async def update_gerty(gerty_id: str, **kwargs) -> Gerty: await db.execute( f"UPDATE gerty.gertys SET {q} WHERE id = ?", (*kwargs.values(), gerty_id) ) - return await get_gerty(gerty_id) + + gerty = await get_gerty(gerty_id) + assert gerty + return gerty async def get_gerty(gerty_id: str) -> Optional[Gerty]: @@ -82,7 +85,7 @@ async def delete_gerty(gerty_id: str) -> None: #############MEMPOOL########### -async def get_mempool_info(endPoint: str, gerty) -> Optional[Mempool]: +async def get_mempool_info(endPoint: str, gerty) -> dict: logger.debug(endPoint) endpoints = MempoolEndpoint() url = "" diff --git a/lnbits/extensions/gerty/helpers.py b/lnbits/extensions/gerty/helpers.py index 24b22b5d3..5897423e4 100644 --- a/lnbits/extensions/gerty/helpers.py +++ b/lnbits/extensions/gerty/helpers.py @@ -3,15 +3,16 @@ import os import random import textwrap from datetime import datetime, timedelta +from typing import List import httpx from loguru import logger -from lnbits.core.crud import get_user, get_wallet_for_key +from lnbits.core.crud import get_wallet_for_key from lnbits.settings import settings from lnbits.utils.exchange_rates import satoshis_amount_as_fiat -from .crud import get_gerty, get_mempool_info +from .crud import get_mempool_info from .number_prefixer import * @@ -24,8 +25,8 @@ def get_percent_difference(current, previous, precision=3): def get_text_item_dict( text: str, font_size: int, - x_pos: int = None, - y_pos: int = None, + x_pos: int = -1, + y_pos: int = -1, gerty_type: str = "Gerty", ): # Get line size by font size @@ -63,12 +64,12 @@ def get_text_item_dict( # logger.debug('multilineText') # logger.debug(multilineText) - text = {"value": multilineText, "size": font_size} - if x_pos is None and y_pos is None: - text["position"] = "center" + data_text = {"value": multilineText, "size": font_size} + if x_pos == -1 and y_pos == -1: + data_text["position"] = "center" else: - text["x"] = x_pos - text["y"] = y_pos + data_text["x"] = x_pos if x_pos > 0 else 0 + data_text["y"] = y_pos if x_pos > 0 else 0 return text @@ -293,8 +294,7 @@ def get_next_update_time(sleep_time_seconds: int = 0, utc_offset: int = 0): def gerty_should_sleep(utc_offset: int = 0): utc_now = datetime.utcnow() local_time = utc_now + timedelta(hours=utc_offset) - hours = local_time.strftime("%H") - hours = int(hours) + hours = int(local_time.strftime("%H")) if hours >= 22 and hours <= 23: return True else: @@ -380,23 +380,19 @@ async def get_mining_stat(stat_slug: str, gerty): async def api_get_mining_stat(stat_slug: str, gerty): - stat = "" + stat = {} if stat_slug == "mining_current_hash_rate": - async with httpx.AsyncClient() as client: - r = await get_mempool_info("hashrate_1m", gerty) - data = r - stat = {} - stat["current"] = data["currentHashrate"] - stat["1w"] = data["hashrates"][len(data["hashrates"]) - 7]["avgHashrate"] + r = await get_mempool_info("hashrate_1m", gerty) + data = r + stat["current"] = data["currentHashrate"] + stat["1w"] = data["hashrates"][len(data["hashrates"]) - 7]["avgHashrate"] elif stat_slug == "mining_current_difficulty": - async with httpx.AsyncClient() as client: - r = await get_mempool_info("hashrate_1m", gerty) - data = r - stat = {} - stat["current"] = data["currentDifficulty"] - stat["previous"] = data["difficulty"][len(data["difficulty"]) - 2][ - "difficulty" - ] + r = await get_mempool_info("hashrate_1m", gerty) + data = r + stat["current"] = data["currentDifficulty"] + stat["previous"] = data["difficulty"][len(data["difficulty"]) - 2][ + "difficulty" + ] return stat @@ -427,10 +423,10 @@ def get_screen_slug_by_index(index: int, screens_list): # Get a list of text items for the screen number -async def get_screen_data(screen_num: int, screens_list: dict, gerty): +async def get_screen_data(screen_num: int, screens_list: list, gerty): screen_slug = get_screen_slug_by_index(screen_num, screens_list) # first get the relevant slug from the display_preferences - areas = [] + areas: List = [] title = "" if screen_slug == "dashboard": @@ -533,9 +529,10 @@ async def get_screen_data(screen_num: int, screens_list: dict, gerty): title = "Lightning Network" areas = await get_lightning_stats(gerty) - data = {} - data["title"] = title - data["areas"] = areas + data = { + "title": title, + "areas": areas, + } return data @@ -598,7 +595,7 @@ async def get_dashboard(gerty): text = [] text.append( get_text_item_dict( - text=await get_time_remaining_next_difficulty_adjustment(gerty), + text=await get_time_remaining_next_difficulty_adjustment(gerty) or "0", font_size=15, gerty_type=gerty.type, ) @@ -630,7 +627,7 @@ async def get_lnbits_wallet_balances(gerty): return wallets -async def get_placeholder_text(): +async def get_placeholder_text(gerty): return [ get_text_item_dict( text="Some placeholder text", @@ -838,14 +835,14 @@ async def get_time_remaining_next_difficulty_adjustment(gerty): r = await get_mempool_info("difficulty_adjustment", gerty) stat = r["remainingTime"] time = get_time_remaining(stat / 1000, 3) - return time + return time async def get_mempool_stat(stat_slug: str, gerty): text = [] if isinstance(gerty.mempool_endpoint, str): if stat_slug == "mempool_tx_count": - r = get_mempool_info("mempool", gerty) + r = await get_mempool_info("mempool", gerty) if stat_slug == "mempool_tx_count": stat = round(r["count"]) text.append( @@ -951,29 +948,3 @@ async def get_mempool_stat(stat_slug: str, gerty): return text -def get_date_suffix(dayNumber): - if 4 <= dayNumber <= 20 or 24 <= dayNumber <= 30: - return "th" - else: - return ["st", "nd", "rd"][dayNumber % 10 - 1] - - -def get_time_remaining(seconds, granularity=2): - intervals = ( - # ('weeks', 604800), # 60 * 60 * 24 * 7 - ("days", 86400), # 60 * 60 * 24 - ("hours", 3600), # 60 * 60 - ("minutes", 60), - ("seconds", 1), - ) - - result = [] - - for name, count in intervals: - value = seconds // count - if value: - seconds -= value * count - if value == 1: - name = name.rstrip("s") - result.append("{} {}".format(round(value), name)) - return ", ".join(result[:granularity]) diff --git a/lnbits/extensions/gerty/models.py b/lnbits/extensions/gerty/models.py index 9ff29bda3..cb19c2bcb 100644 --- a/lnbits/extensions/gerty/models.py +++ b/lnbits/extensions/gerty/models.py @@ -1,5 +1,4 @@ from sqlite3 import Row -from typing import Optional from fastapi import Query from pydantic import BaseModel diff --git a/lnbits/extensions/gerty/views.py b/lnbits/extensions/gerty/views.py index 66194a50a..238e37211 100644 --- a/lnbits/extensions/gerty/views.py +++ b/lnbits/extensions/gerty/views.py @@ -1,10 +1,7 @@ -import json from http import HTTPStatus -from fastapi import Request -from fastapi.params import Depends +from fastapi import Request, Depends from fastapi.templating import Jinja2Templates -from loguru import logger from starlette.exceptions import HTTPException from starlette.responses import HTMLResponse @@ -13,7 +10,6 @@ from lnbits.decorators import check_user_exists from . import gerty_ext, gerty_renderer from .crud import get_gerty -from .views_api import api_gerty_json templates = Jinja2Templates(directory="templates") diff --git a/lnbits/extensions/gerty/views_api.py b/lnbits/extensions/gerty/views_api.py index 7272fb7d0..81c84c1de 100644 --- a/lnbits/extensions/gerty/views_api.py +++ b/lnbits/extensions/gerty/views_api.py @@ -1,24 +1,12 @@ import json -import math -import os -import random -import time -from datetime import datetime from http import HTTPStatus -import httpx -from fastapi import Query -from fastapi.params import Depends -from fastapi.templating import Jinja2Templates -from lnurl import decode as decode_lnurl +from fastapi import Query, Depends from loguru import logger from starlette.exceptions import HTTPException -from lnbits.core.crud import get_user, get_wallet_for_key -from lnbits.core.services import create_invoice -from lnbits.core.views.api import api_payment, api_wallet +from lnbits.core.crud import get_user from lnbits.decorators import WalletTypeInfo, get_key_type, require_admin_key -from lnbits.utils.exchange_rates import satoshis_amount_as_fiat from . import gerty_ext from .crud import ( @@ -29,8 +17,9 @@ from .crud import ( get_mempool_info, update_gerty, ) + from .helpers import * -from .models import Gerty, MempoolEndpoint +from .models import Gerty @gerty_ext.get("/api/v1/gerty", status_code=HTTPStatus.OK) @@ -39,7 +28,8 @@ async def api_gertys( ): wallet_ids = [wallet.wallet.id] if all_wallets: - wallet_ids = (await get_user(wallet.wallet.user)).wallet_ids + user = await get_user(wallet.wallet.user) + wallet_ids = user.wallet_ids if user else [] return [gerty.dict() for gerty in await get_gertys(wallet_ids)] @@ -51,7 +41,6 @@ async def api_link_create_or_update( wallet: WalletTypeInfo = Depends(get_key_type), gerty_id: str = Query(None), ): - logger.debug(data) if gerty_id: gerty = await get_gerty(gerty_id) if not gerty: @@ -91,13 +80,13 @@ async def api_gerty_delete( raise HTTPException(status_code=HTTPStatus.NO_CONTENT) -@gerty_ext.get("/api/v1/gerty/satoshiquote", status_code=HTTPStatus.OK) -async def api_gerty_satoshi(): - return await get_satoshi +# @gerty_ext.get("/api/v1/gerty/satoshiquote", status_code=HTTPStatus.OK) +# async def api_gerty_satoshi(): +# return await get_satoshi @gerty_ext.get("/api/v1/gerty/pages/{gerty_id}/{p}") -async def api_gerty_json(gerty_id: str, p: int = None): # page number +async def api_gerty_json(gerty_id: str, p: int = 0): # page number gerty = await get_gerty(gerty_id) if not gerty: @@ -117,7 +106,7 @@ async def api_gerty_json(gerty_id: str, p: int = None): # page number enabled_screen_count += 1 enabled_screens.append(screen_slug) - logger.debug("Screeens " + str(enabled_screens)) + logger.debug("Screens " + str(enabled_screens)) data = await get_screen_data(p, enabled_screens, gerty) next_screen_number = 0 if ((p + 1) >= enabled_screen_count) else p + 1 diff --git a/pyproject.toml b/pyproject.toml index 573eef1be..fa81bcff3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -93,7 +93,6 @@ exclude = """(?x)( | ^lnbits/extensions/boltz. | ^lnbits/extensions/boltcards. | ^lnbits/extensions/events. - | ^lnbits/extensions/gerty. | ^lnbits/extensions/hivemind. | ^lnbits/extensions/invoices. | ^lnbits/extensions/livestream. From f3e0bd49074e94a192db8e29d441ec6d606d5022 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?dni=20=E2=9A=A1?= Date: Fri, 30 Dec 2022 09:47:49 +0100 Subject: [PATCH 02/10] formatting --- lnbits/extensions/gerty/helpers.py | 6 +----- lnbits/extensions/gerty/views.py | 2 +- lnbits/extensions/gerty/views_api.py | 3 +-- 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/lnbits/extensions/gerty/helpers.py b/lnbits/extensions/gerty/helpers.py index 5897423e4..8c2cc9ead 100644 --- a/lnbits/extensions/gerty/helpers.py +++ b/lnbits/extensions/gerty/helpers.py @@ -390,9 +390,7 @@ async def api_get_mining_stat(stat_slug: str, gerty): r = await get_mempool_info("hashrate_1m", gerty) data = r stat["current"] = data["currentDifficulty"] - stat["previous"] = data["difficulty"][len(data["difficulty"]) - 2][ - "difficulty" - ] + stat["previous"] = data["difficulty"][len(data["difficulty"]) - 2]["difficulty"] return stat @@ -946,5 +944,3 @@ async def get_mempool_stat(stat_slug: str, gerty): ) ) return text - - diff --git a/lnbits/extensions/gerty/views.py b/lnbits/extensions/gerty/views.py index 238e37211..33e95d3e6 100644 --- a/lnbits/extensions/gerty/views.py +++ b/lnbits/extensions/gerty/views.py @@ -1,6 +1,6 @@ from http import HTTPStatus -from fastapi import Request, Depends +from fastapi import Depends, Request from fastapi.templating import Jinja2Templates from starlette.exceptions import HTTPException from starlette.responses import HTMLResponse diff --git a/lnbits/extensions/gerty/views_api.py b/lnbits/extensions/gerty/views_api.py index 81c84c1de..62e92b75e 100644 --- a/lnbits/extensions/gerty/views_api.py +++ b/lnbits/extensions/gerty/views_api.py @@ -1,7 +1,7 @@ import json from http import HTTPStatus -from fastapi import Query, Depends +from fastapi import Depends, Query from loguru import logger from starlette.exceptions import HTTPException @@ -17,7 +17,6 @@ from .crud import ( get_mempool_info, update_gerty, ) - from .helpers import * from .models import Gerty From 6d29cc85b08e3a21b025d361d490a0748fc9c17f Mon Sep 17 00:00:00 2001 From: callebtc <93376500+callebtc@users.noreply.github.com> Date: Tue, 3 Jan 2023 11:35:10 +0100 Subject: [PATCH 03/10] use proper typing --- lnbits/extensions/gerty/crud.py | 6 ++---- lnbits/extensions/gerty/views_api.py | 3 +++ 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/lnbits/extensions/gerty/crud.py b/lnbits/extensions/gerty/crud.py index 3012eeaef..cfa8de116 100644 --- a/lnbits/extensions/gerty/crud.py +++ b/lnbits/extensions/gerty/crud.py @@ -50,15 +50,13 @@ async def create_gerty(wallet_id: str, data: Gerty) -> Gerty: return gerty -async def update_gerty(gerty_id: str, **kwargs) -> Gerty: +async def update_gerty(gerty_id: str, **kwargs) -> Optional[Gerty]: q = ", ".join([f"{field[0]} = ?" for field in kwargs.items()]) await db.execute( f"UPDATE gerty.gertys SET {q} WHERE id = ?", (*kwargs.values(), gerty_id) ) - gerty = await get_gerty(gerty_id) - assert gerty - return gerty + return await get_gerty(gerty_id) async def get_gerty(gerty_id: str) -> Optional[Gerty]: diff --git a/lnbits/extensions/gerty/views_api.py b/lnbits/extensions/gerty/views_api.py index 62e92b75e..b0d4fb9e9 100644 --- a/lnbits/extensions/gerty/views_api.py +++ b/lnbits/extensions/gerty/views_api.py @@ -55,6 +55,9 @@ async def api_link_create_or_update( data.wallet = wallet.wallet.id gerty = await update_gerty(gerty_id, **data.dict()) + assert gerty, HTTPException( + status_code=HTTPStatus.NOT_FOUND, detail="Gerty does not exist" + ) else: gerty = await create_gerty(wallet_id=wallet.wallet.id, data=data) From 24e72d1e48be577815878fce08e62e1bf83a90ab Mon Sep 17 00:00:00 2001 From: callebtc <93376500+callebtc@users.noreply.github.com> Date: Tue, 3 Jan 2023 11:37:43 +0100 Subject: [PATCH 04/10] fix gerty nitpicks --- lnbits/extensions/gerty/helpers.py | 2 +- lnbits/extensions/gerty/views_api.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lnbits/extensions/gerty/helpers.py b/lnbits/extensions/gerty/helpers.py index 8c2cc9ead..cda84dab3 100644 --- a/lnbits/extensions/gerty/helpers.py +++ b/lnbits/extensions/gerty/helpers.py @@ -406,7 +406,7 @@ async def get_satoshi(): quote = satoshiQuotes[random.randint(0, len(satoshiQuotes) - 1)] # logger.debug(quote.text) if len(quote["text"]) > maxQuoteLength: - logger.debug("Quote is too long, getting another") + logger.trace("Quote is too long, getting another") return await get_satoshi() else: return quote diff --git a/lnbits/extensions/gerty/views_api.py b/lnbits/extensions/gerty/views_api.py index b0d4fb9e9..f71bec428 100644 --- a/lnbits/extensions/gerty/views_api.py +++ b/lnbits/extensions/gerty/views_api.py @@ -82,9 +82,9 @@ async def api_gerty_delete( raise HTTPException(status_code=HTTPStatus.NO_CONTENT) -# @gerty_ext.get("/api/v1/gerty/satoshiquote", status_code=HTTPStatus.OK) -# async def api_gerty_satoshi(): -# return await get_satoshi +@gerty_ext.get("/api/v1/gerty/satoshiquote", status_code=HTTPStatus.OK) +async def api_gerty_satoshi(): + return await get_satoshi @gerty_ext.get("/api/v1/gerty/pages/{gerty_id}/{p}") From 19ef282581c61abcbf751cffb26f18bc5beb97b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?dni=20=E2=9A=A1?= Date: Wed, 4 Jan 2023 11:17:30 +0100 Subject: [PATCH 05/10] adding back removed functions --- lnbits/extensions/gerty/helpers.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/lnbits/extensions/gerty/helpers.py b/lnbits/extensions/gerty/helpers.py index 2e9363992..036aa011a 100644 --- a/lnbits/extensions/gerty/helpers.py +++ b/lnbits/extensions/gerty/helpers.py @@ -73,6 +73,34 @@ def get_text_item_dict( return text +def get_date_suffix(dayNumber): + if 4 <= dayNumber <= 20 or 24 <= dayNumber <= 30: + return "th" + else: + return ["st", "nd", "rd"][dayNumber % 10 - 1] + + +def get_time_remaining(seconds, granularity=2): + intervals = ( + # ('weeks', 604800), # 60 * 60 * 24 * 7 + ("days", 86400), # 60 * 60 * 24 + ("hours", 3600), # 60 * 60 + ("minutes", 60), + ("seconds", 1), + ) + + result = [] + + for name, count in intervals: + value = seconds // count + if value: + seconds -= value * count + if value == 1: + name = name.rstrip("s") + result.append("{} {}".format(round(value), name)) + return ", ".join(result[:granularity]) + + # format a number for nice display output def format_number(number, precision=None): return "{:,}".format(round(number, precision)) From 239d35a60a730eb828e33ef6e1df005afb2609b4 Mon Sep 17 00:00:00 2001 From: ben Date: Wed, 4 Jan 2023 11:49:50 +0000 Subject: [PATCH 06/10] trying to fix errors in software gerty --- .../gerty/templates/gerty/gerty.html | 76 +++++++++++-------- 1 file changed, 43 insertions(+), 33 deletions(-) diff --git a/lnbits/extensions/gerty/templates/gerty/gerty.html b/lnbits/extensions/gerty/templates/gerty/gerty.html index d45484a41..b2fb86b62 100644 --- a/lnbits/extensions/gerty/templates/gerty/gerty.html +++ b/lnbits/extensions/gerty/templates/gerty/gerty.html @@ -3,39 +3,39 @@ gertyname }}{% endraw %}{% endblock %}{% block page %} {% raw %}
- {{fun_exchange_market_rate["amount"]}} + {{elements.fun_exchange_market_rate["amount"]}} {{fun_exchange_market_rate["unit"].split(" ")[1]}}{{elements.fun_exchange_market_rate["unit"].split(" ")[1]}}
-

"{{fun_satoshi_quotes["quote"]}}"

- ~ Satoshi {{fun_satoshi_quotes["date"]}} +

"{{elements.fun_satoshi_quotes["quote"]}}"

+ ~ Satoshi {{elements.fun_satoshi_quotes["date"]}}
-
+
@@ -61,40 +61,40 @@ gertyname }}{% endraw %}{% endblock %}{% block page %} {% raw %}
Onchain
-

+

{{item[0].value}}: {{item[1].value}}

- +
Mining
-

+

{{item[0].value}}: {{item[1].value}}

- +
Lightning (Last 7 days)
-

+

{{item[0].value}}: {{item[1].value}}

- +
Servers to check
-
+
@@ -150,10 +150,15 @@ gertyname }}{% endraw %}{% endblock %}{% block page %} {% raw %} mixins: [windowMixin], data: function () { return { - lnbits_wallets_balance: {}, - dashboard_onchain: {}, - fun_satoshi_quotes: {}, - fun_exchange_market_rate: {}, + elements:{ + lnbits_wallets_balance: [], + dashboard_onchain: [], + fun_satoshi_quotes: [], + fun_exchange_market_rate: [], + lightning_dashboard: [], + url_checker: [], + dashboard_mining: [], + }, gerty: [], gerty_id: `{{gerty}}`, gertyname: '', @@ -177,16 +182,20 @@ gertyname }}{% endraw %}{% endblock %}{% block page %} {% raw %} 'GET', `/gerty/api/v1/gerty/pages/${this.gerty_id}/${i}` ) - this.gerty[i] = data + console.log(data.screen.slug) + if(data.screen.slug){ + this.gerty[i] = data + } + } catch (error) { LNbits.utils.notifyApiError(error) } } - console.log(this.gerty) + console.log(this.gerty[0].screen.group) for (let i = 0; i < this.gerty.length; i++) { if (this.gerty[i].screen.group == 'lnbits_wallets_balance') { for (let q = 0; q < this.gerty[i].screen.areas.length; q++) { - this.lnbits_wallets_balance[q] = { + this.elements.lnbits_wallets_balance[q] = { name: this.gerty[i].screen.areas[q][0].value, amount: this.gerty[i].screen.areas[q][1].value, color1: this.walletColors[q].first, @@ -196,35 +205,36 @@ gertyname }}{% endraw %}{% endblock %}{% block page %} {% raw %} } } if (this.gerty[i].screen.group == 'url_checker') { - this.url_checker = this.gerty[i].screen.areas + this.elements.url_checker = this.gerty[i].screen.areas this.gertyname = this.gerty[i].settings.name } if (this.gerty[i].screen.group == 'dashboard_onchain') { - this.dashboard_onchain = this.gerty[i].screen.areas + this.elements.dashboard_onchain = this.gerty[i].screen.areas this.gertyname = this.gerty[i].settings.name } if (this.gerty[i].screen.group == 'dashboard_mining') { - this.dashboard_mining = this.gerty[i].screen.areas + this.elements.dashboard_mining = this.gerty[i].screen.areas this.gertyname = this.gerty[i].settings.name } if (this.gerty[i].screen.group == 'lightning_dashboard') { - this.lightning_dashboard = this.gerty[i].screen.areas + this.elements.lightning_dashboard = this.gerty[i].screen.areas this.gertyname = this.gerty[i].settings.name } if (this.gerty[i].screen.group == 'fun_satoshi_quotes') { - this.fun_satoshi_quotes['quote'] = this.gerty[ + console.log(this.gerty[i]); + this.elements.fun_satoshi_quotes['quote'] = this.gerty[ i ].screen.areas[0][0].value - this.fun_satoshi_quotes['date'] = this.gerty[ + this.elements.fun_satoshi_quotes['date'] = this.gerty[ i ].screen.areas[0][1].value this.gertyname = this.gerty[i].settings.name } if (this.gerty[i].screen.group == 'fun_exchange_market_rate') { - this.fun_exchange_market_rate['unit'] = this.gerty[ + this.elements.fun_exchange_market_rate['unit'] = this.gerty[ i ].screen.areas[0][0].value - this.fun_exchange_market_rate['amount'] = this.gerty[ + this.elements.fun_exchange_market_rate['amount'] = this.gerty[ i ].screen.areas[0][1].value this.gertyname = this.gerty[i].settings.name From 92cfcca1d9c1227e87ce7a717c96ee97ca447f7e Mon Sep 17 00:00:00 2001 From: ben Date: Wed, 4 Jan 2023 15:03:05 +0000 Subject: [PATCH 07/10] replaced with working software gerty --- .../gerty/templates/gerty/gerty.html | 483 +++++++++--------- 1 file changed, 240 insertions(+), 243 deletions(-) diff --git a/lnbits/extensions/gerty/templates/gerty/gerty.html b/lnbits/extensions/gerty/templates/gerty/gerty.html index b2fb86b62..141c3152d 100644 --- a/lnbits/extensions/gerty/templates/gerty/gerty.html +++ b/lnbits/extensions/gerty/templates/gerty/gerty.html @@ -1,254 +1,251 @@ {% extends "public.html" %} {% block toolbar_title %} Gerty: {% raw %}{{ -gertyname }}{% endraw %}{% endblock %}{% block page %} {% raw %} - -
- - - {{elements.fun_exchange_market_rate["amount"]}} - {{elements.fun_exchange_market_rate["unit"].split(" ")[1]}} - - - - + + {{fun_exchange_market_rate["amount"]}} + {{fun_exchange_market_rate["unit"].split(" ")[1]}} + + + + +
+

"{{fun_satoshi_quotes["quote"]}}"

+ ~ Satoshi {{fun_satoshi_quotes["date"]}} +
+
+
+ +
+ + + {{wallet["amount"]}} + ({{wallet["name"]}}) + + +
+ +
-
-

"{{elements.fun_satoshi_quotes["quote"]}}"

- ~ Satoshi {{elements.fun_satoshi_quotes["date"]}} -
- -
- -
- - - {{wallet["amount"]}} - ({{wallet["name"]}}) - - -
- -
- - -
Onchain
-
- -

- {{item[0].value}}: {{item[1].value}} -

-
-
- - - -
Mining
-
- -

- {{item[0].value}}: {{item[1].value}} -

-
-
- - - -
Lightning (Last 7 days)
-
- -

- {{item[0].value}}: {{item[1].value}} -

-
-
- - - -
Servers to check
-
- -
-
- - - - {{item[0].value}} - - - + + +
Onchain
+
+ +

+ {{item[0].value}}: {{item[1].value}} +

+
+
+ + + +
Mining
+
+ +

+ {{item[0].value}}: {{item[1].value}} +

+
+
+ + + +
Lightning (Last 7 days)
+
+ +

+ {{item[0].value}}: {{item[1].value}} +

+
+
+ + + +
Servers to check
+
+ +
+ +
+ + {{item[1].value}} + + + {{item[1].value}} + + + {{item[1].value}} + +
-
- - {{item[1].value}} - - - {{item[1].value}} - - - {{item[1].value}} - -
-
- - -
- -{% endraw %} {% endblock %} {% block scripts %} - -{% endblock %} + }) + + {% endblock %} + \ No newline at end of file From 32b785d790b3b775c1268123c00de233c1172c99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?dni=20=E2=9A=A1?= Date: Wed, 4 Jan 2023 17:01:02 +0100 Subject: [PATCH 08/10] fixes --- lnbits/extensions/gerty/helpers.py | 1 + lnbits/extensions/gerty/views_api.py | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lnbits/extensions/gerty/helpers.py b/lnbits/extensions/gerty/helpers.py index 036aa011a..59b7159d7 100644 --- a/lnbits/extensions/gerty/helpers.py +++ b/lnbits/extensions/gerty/helpers.py @@ -430,6 +430,7 @@ async def get_screen_data(screen_num: int, screens_list: list, gerty): if screen_slug == "dashboard": title = gerty.name areas = await get_dashboard(gerty) + if screen_slug == "lnbits_wallets_balance": wallets = await get_lnbits_wallet_balances(gerty) diff --git a/lnbits/extensions/gerty/views_api.py b/lnbits/extensions/gerty/views_api.py index f71bec428..4020c9806 100644 --- a/lnbits/extensions/gerty/views_api.py +++ b/lnbits/extensions/gerty/views_api.py @@ -17,7 +17,13 @@ from .crud import ( get_mempool_info, update_gerty, ) -from .helpers import * +from .helpers import ( + get_screen_data, + get_satoshi, + gerty_should_sleep, + get_next_update_time, + get_screen_slug_by_index, +) from .models import Gerty @@ -84,7 +90,7 @@ async def api_gerty_delete( @gerty_ext.get("/api/v1/gerty/satoshiquote", status_code=HTTPStatus.OK) async def api_gerty_satoshi(): - return await get_satoshi + return await get_satoshi() @gerty_ext.get("/api/v1/gerty/pages/{gerty_id}/{p}") From 40bcee6d22cfd064c2bde317ff2769e97a08976a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?dni=20=E2=9A=A1?= Date: Wed, 4 Jan 2023 17:09:50 +0100 Subject: [PATCH 09/10] fix issue @ben ;) --- lnbits/extensions/gerty/helpers.py | 3 +- .../gerty/templates/gerty/gerty.html | 499 +++++++++--------- lnbits/extensions/gerty/views_api.py | 4 +- 3 files changed, 256 insertions(+), 250 deletions(-) diff --git a/lnbits/extensions/gerty/helpers.py b/lnbits/extensions/gerty/helpers.py index 59b7159d7..3e48c5763 100644 --- a/lnbits/extensions/gerty/helpers.py +++ b/lnbits/extensions/gerty/helpers.py @@ -70,7 +70,7 @@ def get_text_item_dict( else: data_text["x"] = x_pos if x_pos > 0 else 0 data_text["y"] = y_pos if x_pos > 0 else 0 - return text + return data_text def get_date_suffix(dayNumber): @@ -532,7 +532,6 @@ async def get_screen_data(screen_num: int, screens_list: list, gerty): "title": title, "areas": areas, } - return data diff --git a/lnbits/extensions/gerty/templates/gerty/gerty.html b/lnbits/extensions/gerty/templates/gerty/gerty.html index 141c3152d..8a374e61e 100644 --- a/lnbits/extensions/gerty/templates/gerty/gerty.html +++ b/lnbits/extensions/gerty/templates/gerty/gerty.html @@ -1,251 +1,258 @@ {% extends "public.html" %} {% block toolbar_title %} Gerty: {% raw %}{{ - gertyname }}{% endraw %}{% endblock %}{% block page %} {% raw %} - -
+ - - - {{fun_exchange_market_rate["amount"]}} - {{fun_exchange_market_rate["unit"].split(" ")[1]}} - - - - -
-

"{{fun_satoshi_quotes["quote"]}}"

- ~ Satoshi {{fun_satoshi_quotes["date"]}} -
-
-
- -
- - - {{wallet["amount"]}} - ({{wallet["name"]}}) - - -
- -
+ {{fun_exchange_market_rate["amount"]}} + {{fun_exchange_market_rate["unit"].split(" ")[1]}} + + + + - - -
Onchain
-
- -

- {{item[0].value}}: {{item[1].value}} -

-
-
- - - -
Mining
-
- -

- {{item[0].value}}: {{item[1].value}} -

-
-
- - - -
Lightning (Last 7 days)
-
- -

- {{item[0].value}}: {{item[1].value}} -

-
-
- - - -
Servers to check
-
- -
- -
- - {{item[1].value}} - - - {{item[1].value}} - - - {{item[1].value}} - -
+
+

"{{fun_satoshi_quotes["quote"]}}"

+ ~ Satoshi {{fun_satoshi_quotes["date"]}} +
+ +
+ +
+ + + {{wallet["amount"]}} + ({{wallet["name"]}}) + + +
+ +
+ + +
Onchain
+
+ +

+ {{item[0].value}}: {{item[1].value}} +

+
+
+ + + +
Mining
+
+ +

+ {{item[0].value}}: {{item[1].value}} +

+
+
+ + + +
Lightning (Last 7 days)
+
+ +

+ {{item[0].value}}: {{item[1].value}} +

+
+
+ + + +
Servers to check
+
+ +
+ - - -
- - {% endraw %} {% endblock %} {% block scripts %} - - {% endblock %} - \ No newline at end of file + }, + methods: { + getGertyInfo: async function () { + for (let i = 0; i < 8; i++) { + try { + const {data} = await LNbits.api.request( + 'GET', + `/gerty/api/v1/gerty/pages/${this.gerty_id}/${i}` + ) + this.gerty[i] = data + } catch (error) { + LNbits.utils.notifyApiError(error) + } + } + console.log(this.gerty) + for (let i = 0; i < this.gerty.length; i++) { + if (this.gerty[i].screen.group == 'lnbits_wallets_balance') { + for (let q = 0; q < this.gerty[i].screen.areas.length; q++) { + this.lnbits_wallets_balance[q] = { + name: this.gerty[i].screen.areas[q][0].value, + amount: this.gerty[i].screen.areas[q][1].value, + color1: this.walletColors[q].first, + color2: this.walletColors[q].second + } + this.gertyname = this.gerty[i].settings.name + } + } + if (this.gerty[i].screen.group == 'url_checker') { + this.url_checker = this.gerty[i].screen.areas + this.gertyname = this.gerty[i].settings.name + } + if (this.gerty[i].screen.group == 'dashboard_onchain') { + this.dashboard_onchain = this.gerty[i].screen.areas + this.gertyname = this.gerty[i].settings.name + } + if (this.gerty[i].screen.group == 'dashboard_mining') { + this.dashboard_mining = this.gerty[i].screen.areas + this.gertyname = this.gerty[i].settings.name + } + if (this.gerty[i].screen.group == 'lightning_dashboard') { + this.lightning_dashboard = this.gerty[i].screen.areas + this.gertyname = this.gerty[i].settings.name + } + if (this.gerty[i].screen.group == 'fun_satoshi_quotes') { + this.fun_satoshi_quotes['quote'] = this.gerty[ + i + ].screen.areas[0][0].value + this.fun_satoshi_quotes['date'] = this.gerty[ + i + ].screen.areas[0][1].value + this.gertyname = this.gerty[i].settings.name + } + if (this.gerty[i].screen.group == 'fun_exchange_market_rate') { + this.fun_exchange_market_rate['unit'] = this.gerty[ + i + ].screen.areas[0][0].value + this.fun_exchange_market_rate['amount'] = this.gerty[ + i + ].screen.areas[0][1].value + this.gertyname = this.gerty[i].settings.name + } + } + + setTimeout(this.getGertyInfo, 20000) + this.$forceUpdate() + return this.gerty + } + }, + created: async function () { + await this.getGertyInfo() + } + }) + +{% endblock %} diff --git a/lnbits/extensions/gerty/views_api.py b/lnbits/extensions/gerty/views_api.py index 4020c9806..c408504b6 100644 --- a/lnbits/extensions/gerty/views_api.py +++ b/lnbits/extensions/gerty/views_api.py @@ -18,10 +18,10 @@ from .crud import ( update_gerty, ) from .helpers import ( - get_screen_data, - get_satoshi, gerty_should_sleep, get_next_update_time, + get_satoshi, + get_screen_data, get_screen_slug_by_index, ) from .models import Gerty From 61f415ccee5a352daff4baabaf19bac78b9c7060 Mon Sep 17 00:00:00 2001 From: ben Date: Wed, 4 Jan 2023 19:01:52 +0000 Subject: [PATCH 10/10] software gerty url_checker fixed --- lnbits/extensions/gerty/templates/gerty/gerty.html | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lnbits/extensions/gerty/templates/gerty/gerty.html b/lnbits/extensions/gerty/templates/gerty/gerty.html index 8a374e61e..06a29e225 100644 --- a/lnbits/extensions/gerty/templates/gerty/gerty.html +++ b/lnbits/extensions/gerty/templates/gerty/gerty.html @@ -52,7 +52,7 @@ gertyname }}{% endraw %}{% endblock %}{% block page %} {% raw %}
- - +
Servers to check
@@ -196,7 +195,6 @@ gertyname }}{% endraw %}{% endblock %}{% block page %} {% raw %} LNbits.utils.notifyApiError(error) } } - console.log(this.gerty) for (let i = 0; i < this.gerty.length; i++) { if (this.gerty[i].screen.group == 'lnbits_wallets_balance') { for (let q = 0; q < this.gerty[i].screen.areas.length; q++) {