Beispiel #1
0
    def _save_book_db(self, info):
        logger.info('_save_book_db')

        book = Book.normal.filter(title=info['name']).first()
        if not book:
            book = Book()
        book.title = info.get('name')
        book.author_id = self._save_or_get_author_db(info).id
        book.desc = info.get('desc')
        book.markeup = info.get('markeup')
        book.latest_chapter = info.get('latest_chapter')
        book.origin_addr = self.url
        book.save()
        return book
Beispiel #2
0
    def _save_comic_db(self, info):
        logger.info('_save_comic_db')

        comic = Book.normal.filter(title=info['name'],
                                   book_type=BOOK_TYPE_DESC.Comic).first()
        if not comic:
            comic = Book()
        comic.book_type = BOOK_TYPE_DESC.Comic
        comic.title = info.get('name')
        comic.author_id = self._save_or_get_author_db(info)
        comic.desc = info.get('desc')
        comic.markeup = info.get('markeup')
        comic.title = info.get('name')
        comic.origin_addr = self.url
        comic.save()
        if isinstance(info['cover'], list):
            logger.info('_save_comic_db run loop')
            for index, url in enumerate(info['cover'], 1):
                info = self._save_image_disk(url)
                img, flag = Image.normal.get_or_create(
                    img_type=IMAGE_TYPE_DESC.COVER,
                    key=info['id'],
                    name=info['name'])
                logger.info('_save_comic_db run loop,{}==={}==={}'.format(
                    comic, info, img))
                comic.cover.add(img)

        else:
            info = self._save_image_disk(info['cover'])
            # img = Image(img_type=IMAGE_TYPE_DESC.COMIC_COVER, key=info['id'], name=info['name']).save()
            img, flag = Image.normal.get_or_create(
                img_type=IMAGE_TYPE_DESC.COVER,
                key=info['id'],
                name=info['name'])
            logger.info('_save_comic_db run singal,{}==={}==={}'.format(
                comic, info, img))
            comic.cover.add(img)
        comic.save()
        return comic
Beispiel #3
0
def upd_all_book(book_parser):
    """更新所有小说信息"""
    #global g_books
    #bt = time.time()
    for l in book_parser.book_list:
        l['Alias'] = l['Name'] + '_' + l['Author']
        l['Alias_Host'] = l['Alias'] + '_' + book_parser.host_name
        l['Alias_Author'] = l['Author'] + '_' + book_parser.host_name
        l['is_new_book'] = config.Yes
        l['is_new_bookinfo'] = config.Yes
        l['is_new_contentinfo'] = config.Yes
        l['is_new_author'] = config.Yes
        for b in config.g_books:
            if (l['Alias'].decode(config.SYS_ENCODING)==b['Alias']):
                l['book_id'] = b['id']
                l['is_new_book'] = config.No
                break

        if (l['is_new_book']):
            for a in config.g_authors:
                if (l['Alias_Author'].decode(config.SYS_ENCODING)==a['Alias']):
                    #print l['Author'].decode(config.SYS_ENCODING), a['Name']
                    l['author_id'] = a['id']
                    l['is_new_author'] = config.No
                    break
        for bi in config.g_bookinfos:
            if (l['Alias_Host'].decode(config.SYS_ENCODING)==bi['Alias']):
                l['bookinfo_id'] = bi['id']
                l['is_new_bookinfo'] = config.No
                break
        #if (l.has_key('bookinfo_id')) and (config.g_contentinfos.has_key(l['bookinfo_id'])):
        try:
            if (config.g_contentinfos[l['bookinfo_id']] == l['Content_Url']):
                l['is_new_contentinfo'] = config.No
            #else:
                #config.g_contentinfos[l['bookinfo_id']] = l['Content_Url']
        except KeyError:
            pass

    #print "step 1 use time: %f" % (time.time()-bt)
    #bt = time.time()
    k = 0
    for b in book_parser.book_list:
        if (book_parser.is_origin):
          if (b.has_key('is_new_book') and (b['is_new_book'])):
            if (b.has_key('is_new_author') and (b['is_new_author'])):
                author = Author()
                author.Name = b['Author'].decode(config.SYS_ENCODING)
                author.Alias = b['Alias_Author'].decode(config.SYS_ENCODING)
                author.save()
                b['author_id'] = author.id
                config.g_authors.append(model_to_dict(author))
            book = Book()
            book.Name = b['Name'].decode(config.SYS_ENCODING)
            book.Alias = b['Alias'].decode(config.SYS_ENCODING)
            book.author_id = b['author_id']
            book.save()
            config.g_books.append(model_to_dict(book))
            b['book_id'] = book.id
            b['is_new_book'] = config.No
            b['is_new_author'] = config.No
        if (b.has_key('is_new_bookinfo') and b.has_key('is_new_book')):
          if ((b['is_new_bookinfo']) and (not b['is_new_book'])):
            bookinfo = BookInfo()
            bookinfo.book_id = b['book_id']
            bookinfo.HostName = book_parser.host_name 
            bookinfo.BookUrl = b['Book_Url']
            bookinfo.Alias = b['Alias_Host'].decode(config.SYS_ENCODING)
            bookinfo.LastContent = b['Content'].decode(config.SYS_ENCODING)
            bookinfo.ContentUrl = b['Content_Url']
            bookinfo.LastUpdated = time.time()
            bookinfo.save()
            config.g_bookinfos.append(model_to_dict(bookinfo))
            b['bookinfo_id'] = bookinfo.id
            b['is_new_bookinfo'] = config.No
          """
          else:
            bookinfo = BookInfo.objects.get(id=b['bookinfo_id'])
            bookinfo.LastContent = b['Content'].decode(config.SYS_ENCODING)
            bookinfo.ContentUrl = b['Content_Url']
            bookinfo.LastUpdated = time.strftime('%Y-%m-%d %H:%M',
                                                 time.localtime())
            bookinfo.save()
          """
        if (b.has_key('is_new_contentinfo') and b.has_key('is_new_book')):
          if ((b['is_new_contentinfo']) and (not b['is_new_book'])):
            k = k + 1
            cinfo = ContentInfo()
            cinfo.bookinfo_id = b['bookinfo_id']
            cinfo.LastContent = b['Content'].decode(config.SYS_ENCODING)
            cinfo.ContentUrl = b['Content_Url']
            cinfo.LastUpdated = time.strftime('%Y-%m-%d %H:%M',
                                                 time.localtime())
            cinfo.save()
            config.g_contentinfos[b['bookinfo_id']] = b['Content_Url']
            b['is_new_contentinfo'] = config.No