def temp(self, location, country: str=None):
"""Make sure to get your own API key and put it into data/weather/settings.json
\nYou can get an API key from: www.wunderground.com/weather/api/"""
if country is None:
country = self.settings["defCountry"]
url = "http://api.wunderground.com/api/" + self.settings['api_key'] + "/conditions/q/" + country + "/" + location +".json"
async with aiohttp.get(url) as r:
data = await r.json()
if "current_observation" in data:
tempCO = data["current_observation"].get("temperature_string", False)
tempW = data["current_observation"].get("weather", " ")
tempC = data["current_observation"].get("temp_c", " ")
tempF = data["current_observation"].get("temp_f", " ")
tempH = data["current_observation"].get("relative_humidity", " ")
if tempCO != False:
if self.settings["unit"] == "C":
await self.bot.say("**Weather **{} **Temp.** {}{} **Hum. **{} ".format(tempW, str(tempC), u"\u2103", tempH))
elif self.settings["unit"] == "F":
await self.bot.say("**Weather **{} **Temp.** {}F **Hum. **{} ".format(tempW, str(tempF), tempH))
else:
await self.bot.say("No temperature found")
else:
await self.bot.say("`Please use a US zip code or format like: paris fr\nIf the default country is set to your requesting location just '!temp city' will do.\nThe the default country is set to: {} `".format(self.settings["defCountry"]))
评论列表
文章目录