def search_novel(): keyword = request.args.get('keyword', '') if not keyword: return api_response(code=400, message=u'参数缺失') novel_dao = NovelDAO(g.db, current_app.logger) novels = novel_dao.search_novel(keyword) novels = [novel.to_dict() for novel in novels] return api_response(code=0, data=novels)
def get_state(): """ 查看任务状态 """ id = request.args.get('id') if not id: return api_response(code=400, message=u'参数缺失') task = celery_app.AsyncResult(id) return api_response(code=0, data={'state': task.state, 'info': task.info})
def add(): """ 新增Novel """ name, rule = map(request.form.get, ('name', 'rule')) if not all([name, rule]): return api_response(code=400, message=u'参数缺失') novel_dao = NovelDAO(g.db, current_app.logger) result, obj = novel_dao.add(name, rule) if not result: return api_response(code=500, message=obj) return api_response(code=0, data=obj.to_dict())
def sync_content(): """ 发起章节内容同步 """ id = request.form.get('id', int) async_result = sync_chapters_content.apply_async((id, )) return api_response(code=0, data={'task_id': async_result.id, 'state': async_result.state})
def sync(): """ 发起同步 """ id = request.form.get('id', int) async_result = sync_task.apply_async((id, )) return api_response(code=0, data={'task_id': async_result.id, 'state': async_result.state})
def read(): """ 在线阅读 """ id, novel_id = map(request.args.get, ('id', 'novel_id')) if not (id or novel_id): return api_response(code=400, message=u'参数缺失') chapter_dao = ChapterDAO(g.db, current_app.logger) pre, current, next_ = chapter_dao.read(id, novel_id) data = { 'pre': pre, 'next': next_, 'content': current and current.to_dict() } return api_response(code=0, data=data)
def get_chapter_list(): """ 获取章节列表 """ page, pagesize = _get_page_info() id = request.args.get('id', int) novel_dao = NovelDAO(g.db, current_app.logger) count, chapter_list = novel_dao.get_chapter_list(id, page=page, pagesize=pagesize) c_list = [{ 'id': c.id, 'title': c.title, 'publish_time': datetime.strftime(c.publish_time, '%Y-%m-%d %H:%M') } for c in chapter_list] return api_response(code=0, data={'count': count, 'list': c_list})