weatherMs.py 文件源码

python
阅读 53 收藏 0 点赞 0 评论 0

项目:Mash-Cogs 作者: Canule 项目源码 文件源码
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"]))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号