forecast.py 文件源码

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

项目:sopel-modules 作者: phixion 项目源码 文件源码
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)))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号