コード例 #1
0
    async def on_message_received(self, message: Message):
        user_id = message.user.id
        if '/start' in message.bot_commands:
            return

        if User.count({'id': user_id}) == 0:
            if StartSession.count({'id': user_id}) > 0:
                message_text = 'Please, sign in to Evernote account first: /start'
                error_text = 'User {0} not authorized in Evernote'.format(user_id)
            else:
                message_text = 'Who are you, stranger? Please, send /start command.'
                error_text = 'Unregistered user {0}'.format(user_id)
            self.send_message(message.chat.id, message_text)
            raise TelegramBotError(error_text)

        user = User.get({'id': user_id})
        if not hasattr(user, 'evernote_access_token') or \
           not user.evernote_access_token:
            self.send_message(
                user.telegram_chat_id,
                'You should authorize first. Please, send /start command.'
            )
            raise TelegramBotError(
                'User {0} not authorized in Evernote'.format(user.id)
            )
        user.last_request_time = datetime.datetime.now()
        user.save()
コード例 #2
0
async def list_users(request):
    page = request.GET.get('page', 0)
    page_size = 50
    total_cnt = User.count()
    now = datetime.datetime.now()
    week_ago = now - datetime.timedelta(days=7)
    month_ago = now - datetime.timedelta(days=30)
    weekly_active = User.count({'last_request_time': {'$gte': week_ago}})
    monthly_active = User.count({'last_request_time': {'$gte': month_ago}})
    num_pages = total_cnt / page_size + 1
    all_users = User.find({}, skip=page*page_size, limit=page_size,
                          sort=[('last_request_time', -1)])
    users = [x for x in all_users]
    return aiohttp_jinja2.render_template(
        'users.html',
        request,
        {
            'users': users,
            'num_pages': num_pages,
            'total': total_cnt,
            'monthly_active': monthly_active,
            'weekly_active': weekly_active,
        }
    )
コード例 #3
0
async def list_users(request):
    page = request.GET.get('page', 0)
    page_size = 50
    total_cnt = User.count()
    num_pages = total_cnt / page_size + 1
    users = [
        x for x in User.find({},
                             skip=page * page_size,
                             limit=page_size,
                             sort=[('last_request_time', -1)])
    ]
    return aiohttp_jinja2.render_template('users.html', request, {
        'users': users,
        'num_pages': num_pages,
    })