微信公众号python开发——天气查询


天气查询接口api


http://apistore.baidu.com/astore/serviceinfo/1798.html


解析天气


先用中文得到cityinfo,再根据cityinfo得到cityid,然后利用cityid查询天气。

class CWeather:
    """
    http://apistore.baidu.com/astore/serviceinfo/1798.html
    """
    def getCityInfoDict(self, content):
        quoteStr = urllib.quote(str(content))
        htmlContent = urllib.urlopen(u"http://apistore.baidu.com/microservice/cityinfo?cityname="+quoteStr).read()
        return eval(htmlContent)
        pass

    def getCityWeatherDict(self, cityId):
        htmlContent = urllib.urlopen(u"http://apistore.baidu.com/microservice/weather?cityid="+cityId).read()
        return eval(htmlContent)


效果


图文消息回复请查看本系列之前的文章。

第一步回复天气





第二步回复具体城市名称






你可能感兴趣的:(微信公众号python开发——天气查询)