mirror of
https://github.com/lnbits/lnbits.git
synced 2025-04-22 06:24:24 +02:00
Replaced pytz with utc_offset
This commit is contained in:
parent
65a3e4feb2
commit
e193c4ef47
@ -2,7 +2,6 @@ import textwrap
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
import httpx
|
||||
import pytz
|
||||
from loguru import logger
|
||||
|
||||
from .number_prefixer import *
|
||||
@ -95,7 +94,7 @@ async def get_mining_dashboard(gerty):
|
||||
text = []
|
||||
progress = "{0}%".format(round(r.json()["progressPercent"], 2))
|
||||
text.append(get_text_item_dict("Progress through current epoch", 12))
|
||||
text.append(get_text_item_dict(progress, 20))
|
||||
text.append(get_text_item_dict(progress, 60))
|
||||
areas.append(text)
|
||||
|
||||
# difficulty adjustment
|
||||
@ -114,7 +113,7 @@ async def get_mining_dashboard(gerty):
|
||||
"{0}{1}%".format(
|
||||
"+" if difficultyChange > 0 else "", round(difficultyChange, 2)
|
||||
),
|
||||
20,
|
||||
60,
|
||||
)
|
||||
)
|
||||
areas.append(text)
|
||||
@ -193,19 +192,19 @@ async def get_lightning_stats(gerty):
|
||||
return areas
|
||||
|
||||
|
||||
def get_next_update_time(sleep_time_seconds: int = 0, timezone: str = "Europe/London"):
|
||||
def get_next_update_time(sleep_time_seconds: int = 0, utc_offset: int = 0):
|
||||
utc_now = datetime.utcnow()
|
||||
next_refresh_time = utc_now + timedelta(0, sleep_time_seconds)
|
||||
local_refresh_time = next_refresh_time.astimezone(pytz.timezone(timezone))
|
||||
local_refresh_time = next_refresh_time + timedelta(hours=utc_offset)
|
||||
return "{0} {1}".format(
|
||||
"I'll wake up at" if gerty_should_sleep() else "Next update at",
|
||||
"I'll wake up at" if gerty_should_sleep(utc_offset) else "Next update at",
|
||||
local_refresh_time.strftime("%H:%M on %e %b %Y"),
|
||||
)
|
||||
|
||||
|
||||
def gerty_should_sleep(timezone: str = "Europe/London"):
|
||||
utc_now = pytz.utc.localize(datetime.utcnow())
|
||||
local_time = utc_now.astimezone(pytz.timezone(timezone))
|
||||
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)
|
||||
logger.debug("HOURS")
|
||||
|
@ -129,14 +129,15 @@ async def api_gerty_json(gerty_id: str, p: int = None): # page number
|
||||
|
||||
# get the sleep time
|
||||
sleep_time = gerty.refresh_time if gerty.refresh_time else 300
|
||||
if gerty_should_sleep():
|
||||
utc_offset = gerty.utc_offset if gerty.utc_offset else 0
|
||||
if gerty_should_sleep(utc_offset):
|
||||
sleep_time_hours = 8
|
||||
sleep_time = 60 * 60 * sleep_time_hours
|
||||
|
||||
return {
|
||||
"settings": {
|
||||
"refreshTime": sleep_time,
|
||||
"requestTimestamp": get_next_update_time(sleep_time),
|
||||
"requestTimestamp": get_next_update_time(sleep_time, utc_offset),
|
||||
"nextScreenNumber": next_screen_number,
|
||||
"showTextBoundRect": False,
|
||||
"name": gerty.name,
|
||||
|
14
poetry.lock
generated
14
poetry.lock
generated
@ -664,14 +664,6 @@ python-versions = ">=3.5"
|
||||
[package.extras]
|
||||
cli = ["click (>=5.0)"]
|
||||
|
||||
[[package]]
|
||||
name = "pytz"
|
||||
version = "2022.4"
|
||||
description = "World timezone definitions, modern and historical"
|
||||
category = "main"
|
||||
optional = false
|
||||
python-versions = "*"
|
||||
|
||||
[[package]]
|
||||
name = "PyYAML"
|
||||
version = "5.4.1"
|
||||
@ -933,7 +925,7 @@ testing = ["func-timeout", "jaraco.itertools", "pytest (>=4.6)", "pytest-black (
|
||||
[metadata]
|
||||
lock-version = "1.1"
|
||||
python-versions = "^3.10 | ^3.9 | ^3.8 | ^3.7"
|
||||
content-hash = "401fa2739c9209df26cb1b2defaf90c5a4fcdafacc8eb2627f8d324857870281"
|
||||
content-hash = "2db4d8b644c07a599b10ecdd1d532f8fce5dea7afa0332cbebc9a37223f79ed4"
|
||||
|
||||
[metadata.files]
|
||||
aiofiles = [
|
||||
@ -1466,10 +1458,6 @@ python-dotenv = [
|
||||
{file = "python-dotenv-0.19.0.tar.gz", hash = "sha256:f521bc2ac9a8e03c736f62911605c5d83970021e3fa95b37d769e2bbbe9b6172"},
|
||||
{file = "python_dotenv-0.19.0-py2.py3-none-any.whl", hash = "sha256:aae25dc1ebe97c420f50b81fb0e5c949659af713f31fdb63c749ca68748f34b1"},
|
||||
]
|
||||
pytz = [
|
||||
{file = "pytz-2022.4-py2.py3-none-any.whl", hash = "sha256:2c0784747071402c6e99f0bafdb7da0fa22645f06554c7ae06bf6358897e9c91"},
|
||||
{file = "pytz-2022.4.tar.gz", hash = "sha256:48ce799d83b6f8aab2020e369b627446696619e79645419610b9facd909b3174"},
|
||||
]
|
||||
PyYAML = [
|
||||
{file = "PyYAML-5.4.1-cp27-cp27m-macosx_10_9_x86_64.whl", hash = "sha256:3b2b1824fe7112845700f815ff6a489360226a5609b96ec2190a45e62a9fc922"},
|
||||
{file = "PyYAML-5.4.1-cp27-cp27m-win32.whl", hash = "sha256:129def1b7c1bf22faffd67b8f3724645203b79d8f4cc81f674654d9902cb4393"},
|
||||
|
@ -60,7 +60,6 @@ zipp = "3.5.0"
|
||||
loguru = "0.5.3"
|
||||
cffi = "1.15.0"
|
||||
websocket-client = "1.3.3"
|
||||
pytz = "^2022.4"
|
||||
|
||||
[tool.poetry.dev-dependencies]
|
||||
isort = "^5.10.1"
|
||||
|
@ -33,7 +33,6 @@ pyparsing==3.0.9
|
||||
pypng==0.20220715.0
|
||||
pyqrcode==1.2.1
|
||||
pyscss==1.4.0
|
||||
pytz=2022.4
|
||||
python-dotenv==0.20.0
|
||||
pyyaml==6.0
|
||||
represent==1.6.0.post0
|
||||
|
Loading…
x
Reference in New Issue
Block a user