telegram_avatar/open_weather_map_api.py
async def _get_weather_data(self, city_id: int) -> Tuple[float, str]:
        """
        Method which makes a GET request to OpenWeatherMap API in order to
        get current temperature and weather icon name to your city.
        Returns the tuple of updated weather data (temperature
        and weather icon name).
        Args:
            city_id: the code of the city for which you want to receive
                the weather data.
        Raises:
            WeatherDataDownloadError: if OpenWeatherMap API returns
                response with status code different from 200.
        Returns:
            tuple with current temperature and weather icon name.
        """
        # Necessary information for request which loading in query string
        payload = {
            "id": city_id,
            "appid": self._api_token,
        }
        self._logger.info(
            f"Updating weather information with payload: {payload}"
        )
        # Trying making request
        try:
            response = await self._client_session.get(
                url=self._api_url,
                params=payload,
            )
        except ClientError as request_error:
            self._logger.exception(request_error)
            raise WeatherDataDownloadError(
                "Couldn't update weather data from OpenWeatherMap..."
            )
        # Trying validate response body
        try:
            response_body = await response.json(encoding="utf-8")
            validated_response_body = OpenWeatherMap(**response_body)
        except ValidationError as error:
            self._logger.exception(error)
            raise WeatherDataDownloadError(
                "Couldn't update weather data from OpenWeatherMap..."
            )
        self._logger.info(
            f"New response from weather service. "
            f"Status: {response.status}, body: {validated_response_body}"
        )
        if response.status != 200:
            raise WeatherDataDownloadError(
                "Couldn't update weather data from OpenWeatherMap..."
            )
        # If request is success updating weather data with actual
        new_temperature = validated_response_body.main.temp
        new_icon = validated_response_body.weather[0].icon
        if not self._weather_image_exists(new_icon):
            await self._get_weather_image(new_icon)
        return new_temperature, new_icon

        Method which makes a GET request to OpenWeatherMap API in order to
        get current temperature and weather icon name to your city.
        Returns the tuple of updated weather data (temperature
        and weather icon name).
        Args:
            city_id: the code of the city for which you want to receive
                the weather data.
        Raises:
            WeatherDataDownloadError: if OpenWeatherMap API returns
                response with status code different from 200.
        Returns:
            tuple with current temperature and weather icon name.
        
Method which makes a GET request to OpenWeatherMap API in order to
get current temperature and weather icon name to your city.
Returns the tuple of updated weather data (temperature
and weather icon name).
Method which makes a GET request to OpenWeatherMap API in order to get current temperature and weather icon name to your city . Returns the tuple of updated weather data ( temperature and weather icon name ) .
async def _get_weather_data(self, city_id: int) -> Tuple[float, str]:
        payload = {
            "id": city_id,
            "appid": self._api_token,
        }
        self._logger.info(
            f"Updating weather information with payload: {payload}"
        )
        try:
            response = await self._client_session.get(
                url=self._api_url,
                params=payload,
            )
        except ClientError as request_error:
            self._logger.exception(request_error)
            raise WeatherDataDownloadError(
                "Couldn't update weather data from OpenWeatherMap..."
            )
        try:
            response_body = await response.json(encoding="utf-8")
            validated_response_body = OpenWeatherMap(**response_body)
        except ValidationError as error:
            self._logger.exception(error)
            raise WeatherDataDownloadError(
                "Couldn't update weather data from OpenWeatherMap..."
            )
        self._logger.info(
            f"New response from weather service. "
            f"Status: {response.status}, body: {validated_response_body}"
        )
        if response.status != 200:
            raise WeatherDataDownloadError(
                "Couldn't update weather data from OpenWeatherMap..."
            )
        new_temperature = validated_response_body.main.temp
        new_icon = validated_response_body.weather[0].icon
        if not self._weather_image_exists(new_icon):
            await self._get_weather_image(new_icon)
        return new_temperature, new_icon
async def _get_weather_data ( self , city_id : int ) -> Tuple [ float , str ] : payload = { "id" : city_id , "appid" : self . _api_token , } self . _logger . info ( f"Updating weather information with payload: {payload}" ) try : response = await self . _client_session . get ( url = self . _api_url , params = payload , ) except ClientError as request_error : self . _logger . exception ( request_error ) raise WeatherDataDownloadError ( "Couldn't update weather data from OpenWeatherMap..." ) try : response_body = await response . json ( encoding = "utf-8" ) validated_response_body = OpenWeatherMap ( ** response_body ) except ValidationError as error : self . _logger . exception ( error ) raise WeatherDataDownloadError ( "Couldn't update weather data from OpenWeatherMap..." ) self . _logger . info ( f"New response from weather service. " f"Status: {response.status}, body: {validated_response_body}" ) if response . status != 200 : raise WeatherDataDownloadError ( "Couldn't update weather data from OpenWeatherMap..." ) new_temperature = validated_response_body . main . temp new_icon = validated_response_body . weather [ 0 ] . icon if not self . _weather_image_exists ( new_icon ) : await self . _get_weather_image ( new_icon ) return new_temperature , new_icon
Method which makes a GET request to OpenWeatherMap API in order to
get current temperature and weather icon name to your city.
Method which makes a GET request to OpenWeatherMap API in order to get current temperature and weather icon name to your city .
"""
        Method which makes a GET request to OpenWeatherMap API in order to
        get current temperature and weather icon name to your city.
        Returns the tuple of updated weather data (temperature
        and weather icon name).
        Args:
            city_id: the code of the city for which you want to receive
                the weather data.
        Raises:
            WeatherDataDownloadError: if OpenWeatherMap API returns
                response with status code different from 200.
        Returns:
            tuple with current temperature and weather icon name.
        """ # Necessary information for request which loading in query string # Trying making request # Trying validate response body # If request is success updating weather data with actual
tuple with current temperature and weather icon name.
tuple with current temperature and weather icon name .
if OpenWeatherMap API returns
response with status code different from 200.
if OpenWeatherMap API returns response with status code different from 200 .
WeatherDataDownloadError
self
city_id
int
the code of the city for which you want to receive
the weather data.
the code of the city for which you want to receive the weather data .