- utils/pogoda.py: добавлена API_URL_WEATHER, format_weather_for_embed(), проверка None в format_weather_data_for_console() - utils/morning_runner.py: вынесен MorningData (dataclass) и gather_morning(); run_morning() использует их вместо ручного asyncio.gather - utils/__init__.py: экспортирован публичный API (__all__) - commands/pg.py: убран ручной парсинг погоды, используется format_weather_data_for_console() - console_commands/morning.py: дубликат asyncio.gather заменён на gather_morning() - console_commands/pogoda.py: хардкод URL заменён на API_URL_WEATHER - console_commands/cat.py: заглушка заменена на рабочий вызов fetch_cat() - tests/test_commands_pg.py: обновлён тест fetch_returns_none (бот теперь отправляет сообщение об ошибке вместо молчаливого возврата)
59 lines
2.0 KiB
Python
59 lines
2.0 KiB
Python
from utils.cat import fetch_cat
|
||
from utils.morning_runner import gather_morning
|
||
from utils.news import RSS_URL_ARTICLES, RSS_URL_POSTS, format_articles
|
||
from utils.pogoda import format_weather_data_for_console
|
||
|
||
|
||
async def morning(stop_event, bot):
|
||
"""Вывести погоду, лучшие статьи за сутки и котик"""
|
||
data = await gather_morning()
|
||
|
||
print("Доброе утро!\n")
|
||
|
||
# --- Котик ---
|
||
if data.cat_url:
|
||
print(f"Котик: {data.cat_url}\n")
|
||
else:
|
||
print("Котика получить не удалось.\n")
|
||
|
||
# --- Погода ---
|
||
formatted = format_weather_data_for_console(data.weather)
|
||
if formatted:
|
||
print("**Погода в Магнитогорске:**")
|
||
for line in formatted:
|
||
print(line)
|
||
else:
|
||
print("Не удалось получить данные о погоде.")
|
||
|
||
print()
|
||
|
||
# --- Новости: статьи ---
|
||
if data.articles is not None:
|
||
if data.articles:
|
||
lines = format_articles(
|
||
data.articles,
|
||
"Лучшие статьи за сутки / Искусственный интеллект / Хабr",
|
||
"https://habr.com/ru/hubs/artificial_intelligence/articles/top/daily/",
|
||
)
|
||
print("\n".join(lines))
|
||
else:
|
||
print("Новостей пока нет.")
|
||
else:
|
||
print("Не удалось получить новости.")
|
||
|
||
print()
|
||
|
||
# --- Новости: посты ---
|
||
if data.posts is not None:
|
||
if data.posts:
|
||
lines = format_articles(
|
||
data.posts,
|
||
"Лучшие новости за сутки / Искусственный интеллект / Хабr",
|
||
"https://habr.com/ru/hubs/artificial_intelligence/news/top/daily/",
|
||
)
|
||
print("\n".join(lines))
|
||
else:
|
||
print("Новостей пока нет.")
|
||
else:
|
||
print("Не удалось получить новости.")
|