示例#1
0
def library_origin_view(request,
                        template_name='ebookSystem/library_origin_view.html'):
    if request.method == 'GET':
        if not request.user.is_guest:
            status = 'error'
            message = ''
            return locals()
        book = Book.objects.get(ISBN=request.GET['ISBN'])
        if not book.status == book.STATUS['final']:
            final_epub = book.path + '/OCR/{0}.epub'.format(book.ISBN)
            try:
                part_list = [
                    file.get_clean_file() for file in book.ebook_set.all()
                ]
                from utils.epub import html2epub
                info = {
                    'ISBN': book.book_info.ISBN,
                    'bookname': book.book_info.bookname,
                    'author': book.book_info.author,
                    'date': str(book.book_info.date),
                    'house': book.book_info.house,
                    'language': 'zh',
                }
                html2epub(part_list, final_epub, **info)
            except BaseException as e:
                raise SystemError('epub create fail (not final):' + unicode(e))

        token = uuid.uuid4().hex
        cache.set('token.' + str(request.user.id), token, 10)
        path = '/library_origin_epub/' + book.ISBN + '/' + token
        base64_path = base64.b64encode(path)
        return locals()
示例#2
0
def library_origin_view(request, template_name='ebookSystem/library_origin_view.html'):
	if request.method == 'GET':
		if not request.user.is_guest:
			status = 'error'
			message = ''
			return locals()
		book = Book.objects.get(ISBN=request.GET['ISBN'])
		if not book.status == book.STATUS['final']:
			final_epub = book.path +'/OCR/{0}.epub'.format(book.ISBN)
			try:
				part_list = [ file.get_clean_file() for file in book.ebook_set.all() ]
				from utils.epub import html2epub
				info = {
					'ISBN': book.book_info.ISBN,
					'bookname': book.book_info.bookname,
					'author': book.book_info.author,
					'date': str(book.book_info.date),
					'house': book.book_info.house,
					'language': 'zh',
				}
				html2epub(part_list, final_epub, **info)
			except BaseException as e:
				raise SystemError('epub create fail (not final):' +unicode(e))

		token = uuid.uuid4().hex
		cache.set('token.' +str(request.user.id), token, 10)
		path = '/library_origin_epub/' +book.ISBN +'/' +token
		base64_path = base64.b64encode(path)
		return locals()
示例#3
0
 def realtime_epub_create(self):
     final_epub = self.path + '/OCR/{0}.epub'.format(self.ISBN)
     try:
         part_list = [
             file.get_clean_file() for file in self.ebook_set.all()
         ]
         from utils.epub import html2epub
         info = {
             'ISBN': self.book_info.ISBN,
             'bookname': self.book_info.bookname,
             'author': self.book_info.author,
             'date': str(self.book_info.date),
             'house': self.book_info.house,
             'language': 'zh',
         }
         html2epub(part_list, final_epub, **info)
     except BaseException as e:
         raise SystemError('epub create fail (not final):' + str(e))
示例#4
0
    def custom_epub_create(self, custom_epub, user):
        self.check_status()
        #準備epub文件
        from ebooklib import epub
        from utils.epub import txt2epub, html2epub, add_bookinfo
        info = {
            'ISBN': self.book_info.ISBN,
            'bookname': self.book_info.bookname,
            'author': self.book_info.author,
            'date': str(self.book_info.date),
            'house': self.book_info.house,
            'language': 'zh',
        }
        if self.status == 5 and self.source != 'self':
            final_epub = self.path + '/OCR/{0}.epub'.format(self.ISBN)
            try:
                book = epub.read_epub(final_epub)
                book = add_bookinfo(book, **info)
                book.set_identifier(user.username)
                epub.write_epub(custom_epub, book, {})
            except BaseException as e:
                raise SystemError('epub create fail:' + str(e))
        else:
            final_epub = self.path + '/temp/{0}.temp'.format(self.ISBN)
            final_dir = os.path.dirname(final_epub)
            if not os.path.exists(final_dir):
                os.makedirs(final_dir)
            try:
                part_list = [
                    file.get_clean_file()
                    for file in self.ebook_set.all().order_by('part')
                ]
                html2epub(part_list, final_epub, **info)
                book = epub.read_epub(final_epub)
                book = add_bookinfo(book, **info)
                book.set_identifier(user.username)
                epub.write_epub(custom_epub, book, {})
            except BaseException as e:
                raise SystemError('epub create fail (not final):' + str(e))

        return custom_epub
示例#5
0
	def custom_epub_create(self, custom_epub, user):
		self.check_status()
		#準備epub文件
		from ebooklib import epub
		from utils.epub import txt2epub, html2epub, add_bookinfo
		info = {
			'ISBN': self.book_info.ISBN,
			'bookname': self.book_info.bookname,
			'author': self.book_info.author,
			'date': str(self.book_info.date),
			'house': self.book_info.house,
			'language': 'zh',
		}
		if self.status == 5:
			final_epub = self.path +'/OCR/{0}.epub'.format(self.ISBN)
			try:
				book = epub.read_epub(final_epub)
				book = add_bookinfo(
					book,
					**info
				)
				book.set_identifier(user.username)
				epub.write_epub(custom_epub, book, {})
			except BaseException as e:
				raise SystemError('epub create fail:' +unicode(e))
		else:
			final_epub = self.path +'/temp/{0}.temp'.format(self.ISBN)
			final_dir = os.path.dirname(final_epub)
			if not os.path.exists(final_dir):
				os.mkdir(final_dir)
			try:
				part_list = [ file.get_clean_file() for file in self.ebook_set.all().order_by('part') ]
				html2epub(part_list, final_epub, **info)
				book = epub.read_epub(final_epub)
				book.set_identifier(user.username)
				epub.write_epub(custom_epub, book, {})
			except BaseException as e:
				raise SystemError('epub create fail (not final):' +unicode(e))

		return custom_epub