- pytest.ini для конфигурации тестов - tests/test_pogoda.py — тесты translate_weather, pressure_to_mmhg, wmo_to_russian (93 теста) - tests/test_fetch_cat.py — тесты fetch_cat (10 тестов) - tests/test_fetch_rss.py — тесты fetch_rss (20 тестов) - tests/test_format_articles.py — тесты truncate_title, parse_date, format_articles (24 теста) - tests/test_fetch_weather.py — тесты fetch_weather, fetch_open_meteo (20 тестов) - tests/test_commands_pogoda.py — тесты команды !pogoda (13 тестов) - Обновить AGENTS.md и requirements.txt
19 lines
550 B
Python
19 lines
550 B
Python
import asyncio
|
|
|
|
import requests
|
|
|
|
CAT_API_URL = "https://api.thecatapi.com/v1/images/search"
|
|
|
|
_session = requests.Session()
|
|
|
|
|
|
async def fetch_cat() -> str | None:
|
|
"""Получить URL случайного котика. Вернуть None при ошибке."""
|
|
try:
|
|
response = await asyncio.to_thread(_session.get, CAT_API_URL, timeout=10)
|
|
response.raise_for_status()
|
|
data = response.json()
|
|
return data[0]["url"]
|
|
except (requests.exceptions.RequestException, IndexError, KeyError):
|
|
return None
|