Ejemplo n.º 1
0
def rows2txt():
    db = DdwDb()
    count = db.get_book_count()["count"]

    pageSize = 100
    page = count / pageSize + 1

    for i in range(0, page + 1):
        step = i * pageSize + 94
        rows = db.list(step)
        if rows is not None:
            for item in rows:
                print "book -------------------------------" + str(item["id"])
                path = mkdir(item["id"])
                chs = db.get_chapters(item["id"])
                if chs is not None:
                    for ch in chs:
                        # db.update_book_last_one(item['id'], one['id'], one['title'], one['create_at'])
                        chtext = db.get_chapter_text(ch["id"])
                        if chtext is not None:
                            try:
                                file_path = os.path.join(path, str(ch["id"]))
                                text = htmlstrip(chtext["text"])
                                # write to file
                                write2file(file_path, text)
                                # update chapter size and text
                                db.update_chapter_size(ch["id"], len(text))
                                db.update_chapter_text(ch["id"], text)
                                print ch["id"]
                            except Exception, ex:
                                log("Error: ch " + str(ch["id"]) + " " + str(Exception) + ":" + str(ex))
Ejemplo n.º 2
0
def rows2txt ():
    db = DdwDb()
    count = db.get_book_count()['count']

    pageSize = 100
    page = count / pageSize + 1

    for i in range(0,page+1):
        step = i * pageSize+94
        rows = db.list(step)
        if rows is not None:
            for item in rows:
                print "book -------------------------------" + str(item["id"])
                path = mkdir(item["id"])
                chs = db.get_chapters(item['id'])
                if chs is not None:
                    for ch in chs:
                        #db.update_book_last_one(item['id'], one['id'], one['title'], one['create_at'])
                        chtext = db.get_chapter_text(ch['id'])
                        if chtext is not None:
                            try:
                                file_path = os.path.join(path, str(ch['id']))
                                text = htmlstrip(chtext["text"])
                                #write to file
                                write2file(file_path, text)
                                #update chapter size and text
                                db.update_chapter_size(ch['id'], len(text))
                                db.update_chapter_text(ch['id'], text)
                                print ch['id']
                            except Exception,ex:
                                log("Error: ch "+ str(ch['id']) + " " + str(Exception) + ":" + str(ex) )
Ejemplo n.º 3
0
def save_book (id):
    dw = DdwDb()
    book = dw.get_book(id)
    if book is None:
        print '-------------begin '+ str(id)+'-------------'
        book = get_book_detail(id)

        if book is not None:
            print '-------------saving-------------'
            #author
            author_id = 0
            author = dw.get_author(book['author'])
            if author is None:
                author_id = dw.insert_author(book['author'])
            else:
                author_id = int(author['id'])
            #category
            cate_id = 0
            cate = dw.get_category(book['cate'])
            if cate is None:
                cate_id = dw.insert_category(book['cate'])
            else:
                cate_id = int(cate['id'])
            #book
            desc = book['desc']
            try:
                desc = htmlstrip(desc).strip()
            except Exception,ex:
                log("Error: desc.error")
            dw.insert_book(id, book['name'], desc, author_id, cate_id, book['is_finish'],book['recommend_count'])

            print '-------------end of '+ str(id)+'-----------'
Ejemplo n.º 4
0
Archivo: ddw.py Proyecto: wangjun/novel
def save_book(id):
    dw = DdwDb()
    book = dw.get_book(id)
    if book is None:
        print '-------------begin ' + str(id) + '-------------'
        book = get_book_detail(id)

        if book is not None:
            print '-------------saving-------------'
            #author
            author_id = 0
            author = dw.get_author(book['author'])
            if author is None:
                author_id = dw.insert_author(book['author'])
            else:
                author_id = int(author['id'])
            #category
            cate_id = 0
            cate = dw.get_category(book['cate'])
            if cate is None:
                cate_id = dw.insert_category(book['cate'])
            else:
                cate_id = int(cate['id'])
            #book
            desc = book['desc']
            try:
                desc = htmlstrip(desc).strip()
            except Exception, ex:
                log("Error: desc.error")
            dw.insert_book(id, book['name'], desc, author_id, cate_id,
                           book['is_finish'], book['recommend_count'])

            print '-------------end of ' + str(id) + '-----------'
Ejemplo n.º 5
0
def mkdesc():
    db = DdwDb()
    count = db.get_book_count()["count"]

    pageSize = 100
    page = count / pageSize + 1

    for i in range(0, page + 1):
        step = i * pageSize
        rows = db.list(step)
        if rows is not None:
            for item in rows:
                print "book -------------------------------" + str(item["id"])
                b = db.get_book(item["id"])
                try:
                    desc = htmlstrip(b["description"]).strip()
                    db.update_book_desc(item["id"], desc)
                except Exception, ex:
                    log("Error: mkdesc " + str(item["id"]) + " " + str(Exception) + ":" + str(ex), "desc.error")
Ejemplo n.º 6
0
def mkdesc ():
    db = DdwDb()
    count = db.get_book_count()['count']

    pageSize = 100
    page = count / pageSize + 1

    for i in range(0,page+1):
        step = i * pageSize
        rows = db.list(step)
        if rows is not None:
            for item in rows:
                print "book -------------------------------" + str(item["id"])
                b = db.get_book(item['id'])
                try:
                    desc = htmlstrip(b["description"]).strip()
                    db.update_book_desc(item['id'], desc)
                except Exception,ex:
                    log("Error: mkdesc "+ str(item['id']) + " " + str(Exception) + ":" + str(ex),"desc.error")