예제 #1
0
async def similar_user(request):
    user = request['session'].get('user', None)
    if user:
        try:
            motor_db = motor_base.get_db()
            similar_info = await motor_db.user_recommend.find_one(
                {'user': user})
            if similar_info:
                similar_user = similar_info['similar_user'][:20]
                user_tag = similar_info['user_tag']
                updated_at = similar_info['updated_at']
                return template('similar_user.html',
                                title='与' + user + '相似的书友',
                                is_login=1,
                                is_similar=1,
                                user=user,
                                similar_user=similar_user,
                                user_tag=user_tag,
                                updated_at=updated_at)
            else:
                return template('similar_user.html',
                                title='与' + user + '相似的书友',
                                is_login=1,
                                is_similar=0,
                                user=user)
        except Exception as e:
            LOGGER.error(e)
            return redirect('/')
    else:
        return redirect('/')
예제 #2
0
async def noti_book(request):
    user = request['session'].get('user', None)
    if user:
        try:
            motor_db = motor_base.get_db()
            is_author = 0
            data = await motor_db.user_message.find_one({'user': user}, {
                'author_latest': 1,
                '_id': 0
            })
            if data:
                is_author = 1
                author_list = data.get('author_latest', {})
                return template('noti_book.html',
                                title='新书提醒'.format(user=user),
                                is_login=1,
                                is_author=is_author,
                                author_list=author_list,
                                user=user)
            else:
                return template('noti_book.html',
                                title='新书提醒'.format(user=user),
                                is_login=1,
                                is_author=is_author,
                                user=user)
        except Exception as e:
            LOGGER.error(e)
            return redirect('/')
    else:
        return redirect('/')
예제 #3
0
async def books(request):
    user = request['session'].get('user', None)
    if user:
        try:
            motor_db = motor_base.get_db()
            data = await motor_db.user_message.find_one({'user': user})
            if data:
                books_url = data.get('books_url', None)
                if books_url:
                    result = []
                    for i in books_url:
                        item_result = {}
                        book_url = i.get('book_url', None)
                        last_read_url = i.get("last_read_url", "")
                        book_query = parse_qs(urlparse(book_url).query)
                        last_read_chapter_name = parse_qs(last_read_url).get(
                            'name', ['暂无'])[0]
                        item_result['novels_name'] = book_query.get(
                            'novels_name', '')[0] if book_query.get(
                                'novels_name', '') else ''
                        item_result['book_url'] = book_url
                        latest_data = await motor_db.latest_chapter.find_one(
                            {'owllook_chapter_url': book_url})
                        if latest_data:
                            item_result['latest_chapter_name'] = latest_data[
                                'data']['latest_chapter_name']
                            item_result['owllook_content_url'] = latest_data[
                                'data']['owllook_content_url']
                        else:
                            get_latest_data = await get_the_latest_chapter(
                                book_url) or {}
                            item_result[
                                'latest_chapter_name'] = get_latest_data.get(
                                    'latest_chapter_name', '暂未获取,请反馈')
                            item_result[
                                'owllook_content_url'] = get_latest_data.get(
                                    'owllook_content_url', '')
                        item_result['add_time'] = i.get('add_time', '')
                        item_result[
                            "last_read_url"] = last_read_url if last_read_url else book_url
                        item_result[
                            "last_read_chapter_name"] = last_read_chapter_name
                        result.append(item_result)
                    return template('admin_books.html',
                                    title='{user}的书架'.format(user=user),
                                    is_login=1,
                                    user=user,
                                    is_bookmark=1,
                                    result=result[::-1])
            return template('admin_books.html',
                            title='{user}的书架'.format(user=user),
                            is_login=1,
                            user=user,
                            is_bookmark=0)
        except Exception as e:
            LOGGER.error(e)
            return redirect('/')
    else:
        return redirect('/')
예제 #4
0
async def book_list(request):
    user = request['session'].get('user', None)
    if user:
        try:
            return template('admin_book_list.html',
                            title='{user}的书单'.format(user=user),
                            is_login=1,
                            user=user)
        except Exception as e:
            LOGGER.error(e)
            return redirect('/')
    else:
        return redirect('/')
예제 #5
0
async def bookmarks(request):
    user = request['session'].get('user', None)
    if user:
        try:
            motor_db = motor_base.get_db()
            data = await motor_db.user_message.find_one({'user': user})
            if data:
                # 获取所有书签
                bookmarks = data.get('bookmarks', None)
                if bookmarks:
                    result = []
                    for i in bookmarks:
                        item_result = {}
                        bookmark = i.get('bookmark', None)
                        query = parse_qs(urlparse(bookmark).query)
                        item_result['novels_name'] = query.get(
                            'novels_name', '')[0] if query.get(
                                'novels_name', '') else ''
                        item_result['chapter_name'] = query.get(
                            'name', '')[0] if query.get('name', '') else ''
                        item_result['chapter_url'] = query.get(
                            'chapter_url', '')[0] if query.get(
                                'chapter_url', '') else ''
                        item_result['bookmark'] = bookmark
                        item_result['add_time'] = i.get('add_time', '')
                        result.append(item_result)
                    return template('admin_bookmarks.html',
                                    title='{user}的书签'.format(user=user),
                                    is_login=1,
                                    user=user,
                                    is_bookmark=1,
                                    result=result[::-1])
            return template('admin_bookmarks.html',
                            title='{user}的书签'.format(user=user),
                            is_login=1,
                            user=user,
                            is_bookmark=0)
        except Exception as e:
            LOGGER.error(e)
            return redirect('/')
    else:
        return redirect('/')
예제 #6
0
async def admin_setting(request):
    user = request['session'].get('user', None)
    if user:
        try:
            motor_db = motor_base.get_db()
            data = await motor_db.user.find_one({'user': user})
            if data:
                return template('admin_setting.html',
                                title='{user}的设置'.format(user=user),
                                is_login=1,
                                user=user,
                                register_time=data['register_time'],
                                email=data.get('email', '请尽快绑定邮箱'))
            else:
                return text('未知错误')
        except Exception as e:
            LOGGER.error(e)
            return redirect('/')
    else:
        return redirect('/')