def get_woeid(self, message, user):
if user == '':
user = message.author.name
try:
woeid = self.woeid_db[user.lower()]
query = urllib.parse.quote('select * from weather.forecast where woeid="{}" and u=\'c\''.format(woeid))
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:
await self.client.send_message(message.channel, 'Couldn\'t look up location. The WOEID of {} is: {}'.format(user, woeid))
return
location = results.get('channel').get('title')
await self.client.send_message(message.channel, 'Location of {} is {}'.format(user, location))
except KeyError:
await self.client.send_message(message.channel, 'No location set. You can use .setlocation to set one')
评论列表
文章目录