weather.py 文件源码

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

项目:GLaDOS2 作者: TheComet 项目源码 文件源码
def woeid_search(query):
    """
    Find the first Where On Earth ID for the given query. Result is the etree
    node for the result, so that location data can still be retrieved. Returns
    None if there is no result, or the woeid field is empty.
    """
    glados.log('woeid_search for: "{}"'.format(query))
    query = urllib.parse.quote('select * from geo.places where text="{}"'.format(query))
    query = 'http://query.yahooapis.com/v1/public/yql?q=' + query
    glados.log('Request: {}'.format(query))
    body = urllib.request.urlopen(query).read()
    parsed = xmltodict.parse(body).get('query')
    results = parsed.get('results')
    if results is None or results.get('place') is None:
        return None
    if type(results.get('place')) is list:
        return results.get('place')[0]
    return results.get('place')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号