File size: 763 Bytes
8622a0e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
from datetime import datetime
def log(*args, **kwargs) -> None:
"""
Add datetime to print() for logs.
"""
error = kwargs.pop("error", False)
print( # can replace this with a different logging system
f"[{datetime.now().date().strftime('%Y-%m-%d')},",
f"{datetime.now().strftime('%H:%M:%S')}]",
("[ERROR]" if error else "[INFO]"),
"-",
*args,
**kwargs
) # [2025-3-1, 7:11:30] - Hello world!
def esc_md(text: str) -> str:
"""
Escape markdown.
"""
escape_chars = ['*', '_', '~', '`', '|', '>', '[', ']', '(', ')', '#', '-', '+', '.']
for char in escape_chars:
text = text.replace(char, f'\\{char}') # e.g. replace * with \*
return text |