Ejemplo n.º 1
0
    def _startChapter(self, chapterName):
        logging.debug('Start Chapter: ' + chapterName)
        if self._chapter:
            self._endChapter()

        self._paragraphMightEnd = False
        self._paragraph = ''
        self._chapter = Chapter.Chapter(chapterName)
Ejemplo n.º 2
0
def change_pos(lib_id, chapter_id):
    chapter = Chapter.getChapter(chapter_id)
    data = request.get_data()
    json_data = json.loads(data.decode('utf8'))
    dest_chapter = json_data['dest_chapter']
    dest_position = json_data['dest_position']
    chapter.changePositon(dest_chapter, dest_position)
    return json_return({
        "message": f"修改节点{chapter_id} 到目标节点 {dest_chapter} 位置 {dest_position} 成果"
    }
    )
Ejemplo n.º 3
0
def chapter_info(lib_id, chapter_id):
    chapter = Chapter.getChapter(chapter_id)
    if chapter is None:
        return not_found("没有找到章节")
    if request.method == 'PUT':
        data = request.get_data()
        json_data = json.loads(data.decode('utf8'))
        current_update_id = chapter.update_id
        for name in ('title', 'summary', 'note', 'status', 'chapter_type',
                     'context', 'update_id'):
            if name in json_data:
                if json_data[name]:
                    chapter.__dict__[name] = json_data[name]
        '''
        注意,这里为了防止客户端服务端时间不一,响应时间不一的情况,导致更新乱序(比如自动保存触发的update,后发先至),chapter更新时候需要附带update id,只有update id大于当前update id的情况,才会触发章节更新

        '''
        if chapter.update_id > current_update_id:
            chapter.update()
            return json_return({
                'utime': chapter.utime,
                "message": f"修改章节 {chapter.title} 成功"
            })
        else:
            return json_return({
                'utime': chapter.utime,
                "message": "这是一个过老的更新请求,请设置最新的update id"
            })
    if request.method == 'POST':
        data = request.get_data()
        json_data = json.loads(data.decode('utf8'))
        title = json_data['title']
        summary = json_data['summary']
        new_chapter = chapter.newChapter(title, summary)
        return json_return({
            "chapter": {
                'id': new_chapter.id
            },
            "message": f"新增章节 {title} 成功"
        })

    if request.method == 'DELETE':
        chapter.drop()
        return json_return({"message": f"删除章节 {chapter.title} 成功"})
    # GET
    full = request.args.get("full", "false") == 'true'
    if not full:
        chapter.children = chapter.getChildren()
        chapter.parents = chapter.getParents()
        return json_return(chapter.__dict__)
    else:
        chapter.children = chapter.getChildren(all=True, asList=False)
        chapter.parents = chapter.getParents()
        return json_return(chapter.__dict__)
Ejemplo n.º 4
0
def chapter_library(lib_id):
    if request.method == 'POST':
        data = request.get_data()
        json_data = json.loads(data.decode('utf8'))
        title = json_data['title']
        summary = json_data['summary']
        Chapter.newBook(lib_id, title, summary, None)
        return json_return({"message": f"新增书 {title} 成功"})

    result = []
    with Database() as db:
        for row in db.select(
                "select id from chapter where library_id=%s and parent=0",
            (lib_id, ),
                dict_result=True):
            chapter = Chapter.getChapter(row['id'])
            chapter.cover = None
            result.append({
                k: v
                for k, v in chapter.__dict__.items() if not k.startswith('__')
            })
    return json_return(result)
Ejemplo n.º 5
0
 def inner_sync_books(lib_id):
     Chapter.syncWordCount(lib_id)
     with Database() as db:
         db.execute("update library set status=%s where id=%s",
                    ('synced', lib_id))
Ejemplo n.º 6
0
def chapter_prevew(lib_id, chapter_id):
    chapter = Chapter.getChapter(chapter_id)
    return json_return({
        'context': chapter.preview()
    }
    )
Ejemplo n.º 7
0
from book import Book, Chapter, Setting, BasicMoveList, BreakList

black_stars_rise = Book([
    Chapter(key='introduction',
            title='Introduction',
            file_name='text/introduction.xml'),
    BasicMoveList(key='basicmoves',
                  title='Basic Moves',
                  file_names=[
                      'text/basic_moves/take-a-risk.xml',
                      'text/basic_moves/suffer-harm.xml',
                      'text/basic_moves/keep-it-together.xml',
                      'text/basic_moves/study.xml',
                  ]),
    BreakList(key='breaks',
              title='Breaks',
              file_names=[
                  'text/breaks/basic.xml',
              ]),
    Setting(key='hinnom',
            title='Hinnom Valley',
            file_names=[
                'text/careers/doctor.xml',
                'text/careers/reporter.xml',
                'text/careers/librarian.xml',
                'text/careers/detective.xml',
                'text/careers/professor.xml',
                'text/careers/mechanic.xml',
                'text/careers/priest.xml',
                'text/careers/artist.xml',
                'text/setups/the-mansion-on-the-hill.xml',