tsleepd.py 文件源码

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

项目:trustedsleepbot 作者: gumblex 项目源码 文件源码
def cmd_time(expr, chatid, replyid, msg):
    '''/time - Get time for various timezones'''
    tzs = list(filter(lambda x: x in pytz.all_timezones_set, expr.split()))
    if not tzs:
        if chatid > 0:
            tzs = [USER_CACHE[msg['from']['id']]['timezone']]
        else:
            tzs = [row[0] for row in CONN.execute(
                'SELECT users.timezone FROM users'
                ' INNER JOIN user_chats ON users.id = user_chats.user'
                ' WHERE user_chats.chat = ? GROUP BY users.timezone'
                ' ORDER BY count(users.timezone) DESC, users.timezone ASC',
                (msg['chat']['id'],))]
    if tzs:
        text = [_('The time is:')]
        for tz in tzs:
            usertime = datetime.datetime.now(pytz.timezone(tz))
            text.append(' '.join((
               '??' if tz_is_day(usertime, tz) else '??',
                usertime.strftime('%H:%M'), tz
            )))
        sendmsg('\n'.join(text), chatid, replyid)
    else:
        sendmsg(_("No timezone specified."), chatid, replyid)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号