Esempio n. 1
0
def get_weather():
    with open("./api_key_config.yaml", 'r') as stream:
        data = yaml.safe_load(stream)
        api_key = data['weather']
        location = "Denver, USA"
        observation = OWM(api_key).weather_at_place(location)
        weather = observation.get_weather()
        return str(weather.get_temperature(unit='fahrenheit')['temp'])
Esempio n. 2
0
 def __call__(self, *args, **kwargs):
     super().__call__(*args, **kwargs)
     if self._query:
         try:
             observation = OWM(WEATHER_TOKEN).weather_at_place(self._query)
         except owm_exceptions.OWMError:
             self.send_telegram_message('No such location 😭')
         else:
             weather = observation.get_weather()
             text = WEATHER_TEXT.format(
                 city=observation.get_location().get_name(),
                 status=weather.get_status(),
                 temperature=weather.get_temperature('celsius'),
                 wind=weather.get_wind(),
                 humidity=weather.get_humidity(),
                 pressure=weather.get_pressure(),
             )
             self.prefix = self.get_emoji(weather) + ' ' + self.prefix
             return self.send_telegram_message(text=text)
     else:
         return self.send_telegram_message('Please specify location')
Esempio n. 3
0
 def __call__(self, *args, **kwargs):
     super().__call__(*args, **kwargs)
     if self._query:
         try:
             observation = OWM(WEATHER_TOKEN).weather_at_place(self._query)
         except owm_exceptions.OWMError:
             self.send_telegram_message('No such location 😭')
         else:
             weather = observation.get_weather()
             city = observation.get_location().get_name()
             status = weather.get_status()
             temperature = weather.get_temperature('celsius')
             wind = weather.get_wind()
             humidity = weather.get_humidity()
             pressure = weather.get_pressure()
             text = WEATHER_TEXT.format(city, status, temperature['temp'],
                                        wind['speed'], humidity,
                                        pressure['press'])
             return self.send_telegram_message(text=text)
     else:
         return self.send_telegram_message('Please pecify location')