⏰ fix: timezone конвертация + general topic fix
- Timezone: конвертация в UTC вместо простого удаления tzinfo - General topic: не добавлять message_thread_id для topic_id=1 - Telegram API требует БЕЗ message_thread_id для общего чата - Тест: пост 3 успешно опубликован - Исправлены 2 критические ошибки планировщика Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
parent
3bd7fe0371
commit
63d059ddb0
2 changed files with 11 additions and 7 deletions
|
|
@ -344,7 +344,8 @@ class Scheduler:
|
||||||
'caption': post.text,
|
'caption': post.text,
|
||||||
'parse_mode': 'HTML'
|
'parse_mode': 'HTML'
|
||||||
}
|
}
|
||||||
if post.topic_id:
|
# Не добавляем message_thread_id для general (1) — это общий чат
|
||||||
|
if post.topic_id and post.topic_id > 1:
|
||||||
params['message_thread_id'] = post.topic_id
|
params['message_thread_id'] = post.topic_id
|
||||||
|
|
||||||
async with aiohttp.ClientSession(connector=connector) as http_session:
|
async with aiohttp.ClientSession(connector=connector) as http_session:
|
||||||
|
|
@ -363,7 +364,8 @@ class Scheduler:
|
||||||
'text': post.text,
|
'text': post.text,
|
||||||
'parse_mode': 'HTML'
|
'parse_mode': 'HTML'
|
||||||
}
|
}
|
||||||
if post.topic_id:
|
# Не добавляем message_thread_id для general (1) — это общий чат
|
||||||
|
if post.topic_id and post.topic_id > 1:
|
||||||
params['message_thread_id'] = post.topic_id
|
params['message_thread_id'] = post.topic_id
|
||||||
|
|
||||||
async with aiohttp.ClientSession(connector=connector) as http_session:
|
async with aiohttp.ClientSession(connector=connector) as http_session:
|
||||||
|
|
|
||||||
|
|
@ -889,11 +889,13 @@ async def api_create_scheduled_post(
|
||||||
# Парсим время
|
# Парсим время
|
||||||
scheduled_dt = datetime.fromisoformat(scheduled_time)
|
scheduled_dt = datetime.fromisoformat(scheduled_time)
|
||||||
|
|
||||||
# Убираем timezone если есть
|
# Если есть timezone - конвертируем в UTC
|
||||||
if scheduled_dt.tzinfo is not None:
|
if scheduled_dt.tzinfo is not None:
|
||||||
scheduled_dt = scheduled_dt.replace(tzinfo=None)
|
from datetime import timezone as tz
|
||||||
|
scheduled_dt = scheduled_dt.astimezone(tz.utc).replace(tzinfo=None)
|
||||||
|
logger.info(f"⏰ Время конвертирована в UTC: {scheduled_dt}")
|
||||||
|
|
||||||
# Проверяем что время в будущем
|
# Проверяем что время в будущем (по UTC)
|
||||||
if scheduled_dt < datetime.utcnow():
|
if scheduled_dt < datetime.utcnow():
|
||||||
return JSONResponse({
|
return JSONResponse({
|
||||||
"success": False,
|
"success": False,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue