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')
评论列表
文章目录