Basic database function implemented
This commit is contained in:
12
util.py
12
util.py
@@ -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
|
||||
Reference in New Issue
Block a user