Added !tokens commands basic implementation

This commit is contained in:
2026-08-21 08:29:23 +03:00
parent 0ae0f8ca53
commit 3b4e9d6a1e
2 changed files with 75 additions and 1 deletions

37
util.py
View File

@@ -8,6 +8,7 @@ import os
import json
import logging
import traceback
import datetime
from html.parser import HTMLParser
from pathlib import Path
from urllib.parse import urlparse
@@ -161,4 +162,38 @@ def check_and_remove_html(possible_html: str) -> tuple[bool, str]:
except:
traceback.print_exc()
return (False, possible_html)
return (False, possible_html)
def date_to_text(date: datetime.datetime, dow: bool = True, seconds: bool = True) -> str:
''' Returns date as formatted string.
Day of week can be added.
Seconds can be added.
'''
if type(date) is float:
date = int(date)
if type(date) is int:
date = datetime.datetime.utcfromtimestamp(date)
# format string
format_string = ''
if dow:
format_string += '%a, '
format_string += '%d.%m.%Y, %H:%M'
if seconds:
format_string += ':%S'
# day of week to Russian
translate_map = [
('Mon', 'Пн'),
('Tue', 'Вт'),
('Wed', 'Ср'),
('Thu', 'Чт'),
('Fri', 'Пт'),
('Sat', 'Сб'),
('Sun', 'Вс')
]
result = date.strftime(format_string)
for en, ru in translate_map:
if en in result:
result = result.replace(en, ru)
break
return result