diff --git a/src/clients/news.py b/src/clients/news.py new file mode 100644 index 0000000..e69de29 diff --git a/src/collectors/collector.py b/src/collectors/collector.py index ebadf7e..82b0f65 100644 --- a/src/collectors/collector.py +++ b/src/collectors/collector.py @@ -103,6 +103,9 @@ async def read(cls) -> Optional[list[CountryDTO]]: population=item["population"], subregion=item["subregion"], timezones=item["timezones"], + area=item["area"], + latitude=item["latitude"], + longitude=item["longitude"], ) ) @@ -219,6 +222,9 @@ async def read(cls, location: LocationDTO) -> Optional[WeatherInfoDTO]: humidity=result["main"]["humidity"], wind_speed=result["wind"]["speed"], description=result["weather"][0]["description"], + visibility=result["visibility"], + dt=result["dt"], + timezone=result["timezone"] // 3600, ) return None diff --git a/src/collectors/models.py b/src/collectors/models.py index 7e36198..ef896ca 100644 --- a/src/collectors/models.py +++ b/src/collectors/models.py @@ -3,6 +3,7 @@ """ from pydantic import Field, BaseModel +from datetime import datetime class HashableBaseModel(BaseModel): @@ -93,6 +94,7 @@ class CountryDTO(BaseModel): timezones=[ "UTC+02:00", ], + area=228, ) """ @@ -106,6 +108,10 @@ class CountryDTO(BaseModel): population: int subregion: str timezones: list[str] + area: float | None + latitude: float | None + longitude: float | None + timezones: list[str] class CurrencyRatesDTO(BaseModel): @@ -148,6 +154,9 @@ class WeatherInfoDTO(BaseModel): humidity: int wind_speed: float description: str + visibility: int + dt: datetime + timezone: int class LocationInfoDTO(BaseModel): diff --git a/src/renderer.py b/src/renderer.py index 8b90dcc..b4ff94f 100644 --- a/src/renderer.py +++ b/src/renderer.py @@ -28,15 +28,38 @@ async def render(self) -> tuple[str, ...]: :return: Результат форматирования """ - return ( - f"Страна: {self.location_info.location.name}", - f"Столица: {self.location_info.location.capital}", - f"Регион: {self.location_info.location.subregion}", - f"Языки: {await self._format_languages()}", - f"Население страны: {await self._format_population()} чел.", - f"Курсы валют: {await self._format_currency_rates()}", - f"Погода: {self.location_info.weather.temp} °C", + values = { + "Страна": self.location_info.location.name, + "Столица": self.location_info.location.capital, + "Регион": self.location_info.location.subregion, + "Языки": await self._format_languages(), + "Население страны": await self._format_population(), + "Курсы валют": await self._format_currency_rates(), + "Площадь страны": self.location_info.location.area, + "Широта": self.location_info.location.latitude, + "Долгота": self.location_info.location.longitude, + "Погода": self.location_info.weather.temp, + "Время": self.location_info.weather.dt.strftime("%d.%m.%Y %H:%M"), + "Часовой пояс": self.location_info.weather.timezone, + "Описание погоды": self.location_info.weather.description, + "Видимость": self.location_info.weather.visibility, + "Влажность": self.location_info.weather.humidity, + "Скорость ветра": self.location_info.weather.wind_speed, + "Давление": self.location_info.weather.pressure, + } + + first_column_width = max(len(key) for key in values) + 1 + second_column_width = max(len(str(value)) for value in values.values()) + 1 + formatted_values = [("-" * (first_column_width + second_column_width + 3))] + formatted_values.extend( + [ + f"|{key:<{first_column_width}}|{value:>{second_column_width}}|" + for key, value in values.items() + ] ) + formatted_values.append("-" * (first_column_width + second_column_width + 3)) + + return tuple(formatted_values) async def _format_languages(self) -> str: """ diff --git a/src/settings.py b/src/settings.py index 4559f84..6aa03c9 100644 --- a/src/settings.py +++ b/src/settings.py @@ -20,6 +20,7 @@ # ключи для доступа к API API_KEY_APILAYER: Optional[str] = os.getenv("API_KEY_APILAYER") API_KEY_OPENWEATHER: Optional[str] = os.getenv("API_KEY_OPENWEATHER") +API_KEY_NEWS: Optional[str] = os.getenv("API_KEY_NEWS") # время актуальности данных о странах (в секундах), по умолчанию – один год CACHE_TTL_COUNTRY: int = int(os.getenv("CACHE_TTL_COUNTRY", "31_536_000"))