Добавил таймауты для API-запросов, уточнил парсинг тегов и типизацию аргументов
This commit is contained in:
9
utils.py
9
utils.py
@@ -3,7 +3,6 @@ from datetime import datetime, timedelta
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
from typing import Optional
|
||||
|
||||
from colorama import Fore
|
||||
|
||||
@@ -29,16 +28,18 @@ def today_end() -> datetime:
|
||||
return datetime(year=year, month=month, day=day, hour=23)
|
||||
|
||||
|
||||
def str_to_date(date: str) -> Optional[datetime]:
|
||||
def str_to_date(date: str) -> datetime | None:
|
||||
if date:
|
||||
return datetime.strptime(date + "T00:00:00Z", config.DATETIME_FORMAT)
|
||||
|
||||
def format_date(date: datetime) -> datetime:
|
||||
def format_date(date: datetime) -> str | None:
|
||||
if date:
|
||||
return date.strftime(config.DATETIME_FORMAT)
|
||||
|
||||
def parse_task_id(tag: str) -> int:
|
||||
return int(re.search(r"^(?P<task_id>\d{5})", tag).group("task_id"))
|
||||
if match := re.search(r"^(?P<task_id>\d{5})", tag):
|
||||
return int(match.group("task_id"))
|
||||
raise ValueError(f'Тег "{tag}" должен начинаться с номера задачи из 5 цифр')
|
||||
|
||||
def db_update():
|
||||
from config import clock, db, red
|
||||
|
||||
Reference in New Issue
Block a user