diff --git a/lnbits/extensions/gerty/helpers.py b/lnbits/extensions/gerty/helpers.py index dd87ef5c..3debab8e 100644 --- a/lnbits/extensions/gerty/helpers.py +++ b/lnbits/extensions/gerty/helpers.py @@ -79,101 +79,98 @@ def format_number(number, precision=None): async def get_mining_dashboard(gerty): areas = [] if isinstance(gerty.mempool_endpoint, str): - async with httpx.AsyncClient() as client: - # current hashrate - r = await get_mempool_info("hashrate_1w", gerty) - data = r - hashrateNow = data["currentHashrate"] - hashrateOneWeekAgo = data["hashrates"][6]["avgHashrate"] + # current hashrate + r = await get_mempool_info("hashrate_1w", gerty) + data = r + hashrateNow = data["currentHashrate"] + hashrateOneWeekAgo = data["hashrates"][6]["avgHashrate"] - text = [] - text.append( - get_text_item_dict( - text="Current mining hashrate", font_size=12, gerty_type=gerty.type - ) + text = [] + text.append( + get_text_item_dict( + text="Current mining hashrate", font_size=12, gerty_type=gerty.type ) - text.append( - get_text_item_dict( - text="{0}hash".format(si_format(hashrateNow, 6, True, " ")), - font_size=20, - gerty_type=gerty.type, - ) + ) + text.append( + get_text_item_dict( + text="{0}hash".format(si_format(hashrateNow, 6, True, " ")), + font_size=20, + gerty_type=gerty.type, ) - text.append( - get_text_item_dict( - text="{0} vs 7 days ago".format( - get_percent_difference(hashrateNow, hashrateOneWeekAgo, 3) - ), - font_size=12, - gerty_type=gerty.type, - ) + ) + text.append( + get_text_item_dict( + text="{0} vs 7 days ago".format( + get_percent_difference(hashrateNow, hashrateOneWeekAgo, 3) + ), + font_size=12, + gerty_type=gerty.type, ) - areas.append(text) + ) + areas.append(text) - r = await get_mempool_info("difficulty_adjustment", gerty) + r = await get_mempool_info("difficulty_adjustment", gerty) - # timeAvg - text = [] - progress = "{0}%".format(round(r["progressPercent"], 2)) - text.append( - get_text_item_dict( - text="Progress through current epoch", - font_size=12, - gerty_type=gerty.type, - ) + # timeAvg + text = [] + progress = "{0}%".format(round(r["progressPercent"], 2)) + text.append( + get_text_item_dict( + text="Progress through current epoch", + font_size=12, + gerty_type=gerty.type, ) - text.append( - get_text_item_dict(text=progress, font_size=60, gerty_type=gerty.type) - ) - areas.append(text) + ) + text.append( + get_text_item_dict(text=progress, font_size=60, gerty_type=gerty.type) + ) + areas.append(text) - # difficulty adjustment - text = [] - stat = r["remainingTime"] - text.append( - get_text_item_dict( - text="Time to next difficulty adjustment", - font_size=12, - gerty_type=gerty.type, - ) + # difficulty adjustment + text = [] + stat = r["remainingTime"] + text.append( + get_text_item_dict( + text="Time to next difficulty adjustment", + font_size=12, + gerty_type=gerty.type, ) - text.append( - get_text_item_dict( - text=get_time_remaining(stat / 1000, 3), - font_size=12, - gerty_type=gerty.type, - ) + ) + text.append( + get_text_item_dict( + text=get_time_remaining(stat / 1000, 3), + font_size=12, + gerty_type=gerty.type, ) - areas.append(text) + ) + areas.append(text) - # difficultyChange - text = [] - difficultyChange = round(r["difficultyChange"], 2) - text.append( - get_text_item_dict( - text="Estimated difficulty change", - font_size=12, - gerty_type=gerty.type, - ) + # difficultyChange + text = [] + difficultyChange = round(r["difficultyChange"], 2) + text.append( + get_text_item_dict( + text="Estimated difficulty change", + font_size=12, + gerty_type=gerty.type, ) - text.append( - get_text_item_dict( - text="{0}{1}%".format( - "+" if difficultyChange > 0 else "", round(difficultyChange, 2) - ), - font_size=60, - gerty_type=gerty.type, - ) + ) + text.append( + get_text_item_dict( + text="{0}{1}%".format( + "+" if difficultyChange > 0 else "", round(difficultyChange, 2) + ), + font_size=60, + gerty_type=gerty.type, ) - areas.append(text) + ) + areas.append(text) - 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 = {} + stat["current"] = data["currentDifficulty"] + stat["previous"] = data["difficulty"][len(data["difficulty"]) - 2]["difficulty"] return areas @@ -456,6 +453,43 @@ async def get_screen_data(screen_num: int, screens_list: dict, gerty): ) ) areas.append(text) + elif screen_slug == "url_checker": + for url in json.loads(gerty.urls): + async with httpx.AsyncClient() as client: + text = [] + try: + response = await client.get(url) + text.append( + get_text_item_dict( + text=url, + font_size=20, + gerty_type=gerty.type, + ) + ) + text.append( + get_text_item_dict( + text=str(response.status_code), + font_size=40, + gerty_type=gerty.type, + ) + ) + except: + text = [] + text.append( + get_text_item_dict( + text=url, + font_size=20, + gerty_type=gerty.type, + ) + ) + text.append( + get_text_item_dict( + text=str("DOWN"), + font_size=40, + gerty_type=gerty.type, + ) + ) + areas.append(text) elif screen_slug == "fun_satoshi_quotes": areas.append(await get_satoshi_quotes(gerty)) elif screen_slug == "fun_exchange_market_rate": @@ -940,8 +974,3 @@ def get_time_remaining(seconds, granularity=2): name = name.rstrip("s") result.append("{} {}".format(round(value), name)) return ", ".join(result[:granularity]) - - -async def get_urls_to_watch(gerty): - gerty = await get_gerty(gerty) - return json.loads(gerty.urls) \ No newline at end of file diff --git a/lnbits/extensions/gerty/migrations.py b/lnbits/extensions/gerty/migrations.py index 2e441c18..654dfcbf 100644 --- a/lnbits/extensions/gerty/migrations.py +++ b/lnbits/extensions/gerty/migrations.py @@ -51,8 +51,9 @@ async def m004_initial(db): """ ) + async def m005_add_gerty_model_col(db): """ support for Gerty model col """ - await db.execute("ALTER TABLE gerty.gertys ADD COLUMN urls TEXT DEFAULT '';") \ No newline at end of file + await db.execute("ALTER TABLE gerty.gertys ADD COLUMN urls TEXT;") diff --git a/lnbits/extensions/gerty/models.py b/lnbits/extensions/gerty/models.py index 07c1f41a..9ff29bda 100644 --- a/lnbits/extensions/gerty/models.py +++ b/lnbits/extensions/gerty/models.py @@ -45,4 +45,4 @@ class Mempool(BaseModel): mempool_endpoint: str = Query(None) endpoint: str = Query(None) data: str = Query(None) - time: int = Query(None) \ No newline at end of file + time: int = Query(None) diff --git a/lnbits/extensions/gerty/templates/gerty/_api_docs.html b/lnbits/extensions/gerty/templates/gerty/_api_docs.html index 27029028..0cea6693 100644 --- a/lnbits/extensions/gerty/templates/gerty/_api_docs.html +++ b/lnbits/extensions/gerty/templates/gerty/_api_docs.html @@ -12,6 +12,6 @@ >

diff --git a/lnbits/extensions/gerty/templates/gerty/gerty.html b/lnbits/extensions/gerty/templates/gerty/gerty.html
index 2aad6104..7efb6c91 100644
--- a/lnbits/extensions/gerty/templates/gerty/gerty.html
+++ b/lnbits/extensions/gerty/templates/gerty/gerty.html
@@ -13,12 +13,14 @@ gertyname }}{% endraw %}{% endblock %}{% block page %} {% raw %}
>
+ {{item[0].value.slice(0, 20)}}...:
+