mirror of
https://github.com/lnbits/lnbits.git
synced 2025-10-06 18:02:38 +02:00
Revert "remove duplicit functions "
This commit is contained in:
@@ -301,6 +301,34 @@ def gerty_should_sleep(utc_offset: int = 0):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
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])
|
||||||
|
|
||||||
|
|
||||||
async def get_mining_stat(stat_slug: str, gerty):
|
async def get_mining_stat(stat_slug: str, gerty):
|
||||||
text = []
|
text = []
|
||||||
if stat_slug == "mining_current_hash_rate":
|
if stat_slug == "mining_current_hash_rate":
|
||||||
|
@@ -131,6 +131,53 @@ async def check_address_balance(charge_id: str) -> Optional[Charges]:
|
|||||||
################## SETTINGS ###################
|
################## SETTINGS ###################
|
||||||
|
|
||||||
|
|
||||||
|
async def save_theme(data: SatsPayThemes, css_id: str = None):
|
||||||
|
# insert or update
|
||||||
|
if css_id:
|
||||||
|
await db.execute(
|
||||||
|
"""
|
||||||
|
UPDATE satspay.themes SET custom_css = ?, title = ? WHERE css_id = ?
|
||||||
|
""",
|
||||||
|
(data.custom_css, data.title, css_id),
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
css_id = urlsafe_short_hash()
|
||||||
|
await db.execute(
|
||||||
|
"""
|
||||||
|
INSERT INTO satspay.themes (
|
||||||
|
css_id,
|
||||||
|
title,
|
||||||
|
user,
|
||||||
|
custom_css
|
||||||
|
)
|
||||||
|
VALUES (?, ?, ?, ?)
|
||||||
|
""",
|
||||||
|
(
|
||||||
|
css_id,
|
||||||
|
data.title,
|
||||||
|
data.user,
|
||||||
|
data.custom_css,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
return await get_theme(css_id)
|
||||||
|
|
||||||
|
|
||||||
|
async def get_theme(css_id: str) -> SatsPayThemes:
|
||||||
|
row = await db.fetchone("SELECT * FROM satspay.themes WHERE css_id = ?", (css_id,))
|
||||||
|
return SatsPayThemes.from_row(row) if row else None
|
||||||
|
|
||||||
|
|
||||||
|
async def get_themes(user_id: str) -> List[SatsPayThemes]:
|
||||||
|
rows = await db.fetchall(
|
||||||
|
"""SELECT * FROM satspay.themes WHERE "user" = ? ORDER BY "timestamp" DESC """,
|
||||||
|
(user_id,),
|
||||||
|
)
|
||||||
|
return await get_config(row.user)
|
||||||
|
|
||||||
|
|
||||||
|
################## SETTINGS ###################
|
||||||
|
|
||||||
|
|
||||||
async def save_theme(data: SatsPayThemes, css_id: str = None):
|
async def save_theme(data: SatsPayThemes, css_id: str = None):
|
||||||
# insert or update
|
# insert or update
|
||||||
if css_id:
|
if css_id:
|
||||||
|
Reference in New Issue
Block a user