Basic database function implemented

This commit is contained in:
Nikita Tyukalov, ASUS, Linux
2026-08-25 21:13:27 +03:00
parent ff6656fdb0
commit ddc1c36c72
7 changed files with 360 additions and 63 deletions

12
util.py
View File

@@ -8,6 +8,7 @@ import os
import logging
import traceback
import datetime
import hashlib
import aioconsole
@@ -75,7 +76,7 @@ async def get_password() -> str | None:
return None
return await ainput("Matrix password: ")
def date_to_text(date: datetime.datetime, dow: bool = True, seconds: bool = True) -> str:
def date_to_text(date: datetime.datetime | float, dow: bool = True, seconds: bool = True) -> str:
''' Returns date as formatted string.
Day of week can be added.
Seconds can be added.
@@ -102,9 +103,14 @@ def date_to_text(date: datetime.datetime, dow: bool = True, seconds: bool = True
('Sat', 'Сб'),
('Sun', 'Вс')
]
result = date.strftime(format_string)
result = date.strftime(format_string) # type: ignore
for en, ru in translate_map:
if en in result:
result = result.replace(en, ru)
break
return result
return result
def get_hash(data: bytes | str) -> str:
if type(data) is str:
data = data.encode(errors="ignore")
return hashlib.sha256(data).hexdigest() # type: ignore