def weather7(bot,trigger):
location = trigger.group(2)
if not location:
location, forecast, postal, error = get_forecast(bot,trigger)
else:
location, forecast, postal, error = get_forecast(bot,trigger,location)
if error:
return
summary = forecast.json()['daily']['summary']
sevendays = []
weekdays = {1:'M',2:'Tu',3:'W',4:'Th',5:'F',6:'Sa',7:'Su'}
for day in forecast.json()['daily']['data']:
wkday = weekdays[datetime.fromtimestamp(int(day['time'])).isoweekday()]
maxtemp = round(day['temperatureMax'])
mintemp = round(day['temperatureMin'])
sevendays.append("{0}:({1}|{2})".format(wkday,mintemp,maxtemp))
del sevendays[0]
sevendays = ", ".join(sevendays)
bot.say("{0}: [{1}] {2}".format(location, summary, str(sevendays)))
评论列表
文章目录