def weather(bot, update, args): """Define weather at certain location""" user = update.message.from_user bot_instance = BotTelegramCore.instance() if bot_instance.is_from_oficial_chat(update): if not CommandCall.allow_call(command=CommandCall.CLIMA): last_call = CommandCall.last_clima() bot.sendMessage(chat_id=user.id, text=COMMAND_THROTTLED.format( segundos=last_call.cooldown_left, comando=last_call.value)) return api_key = config('OPENWEATHERMAP_TOKEN') owm = pyowm.OWM(api_key) text_location = " ".join(args) try: observation = owm.weather_at_place(text_location) _weather = observation.get_weather() humidity = _weather.get_humidity() wind = _weather.get_wind() temp = _weather.get_temperature('celsius') update.message.reply_text(f"🧭 Localização: {text_location}\n" f"🔥️ Temp. Maxima: " f"{temp.get('temp_max')} °C \n" f"❄️ Temp. Minima: " f"{temp.get('temp_min')} °C \n" f"💨 Vel. do Vento: " f"{wind.get('speed')} m/s \n" f"💧 Humidade: " f"{humidity}%") if bot_instance.is_from_oficial_chat(update): CommandCall.clima(user.username) except NotFoundError: update.message.reply_text(f"⚠️ Não consegui localizar a cidade " f"{text_location}!") except APICallError: update.message.reply_text(f"⚠️ Você precisa digitar uma cidade")
def test_clima(self): CommandCall.clima('123') self.assertAlmostEqual(CommandCall.objects.count(), 1) self.assertEqual(CommandCall.objects.first()._value, CommandCall.CLIMA)