Пример #1
0
 def get_illus(self, cxt_data):
     self.page.div()#class_='section'
     # 获取最大图片信息
     orig = cxt_data.get('size').get('orig')
     # 获取中等[medium]图片信息
     medium = self.get_cxt_pic(cxt_data)
     if medium == None:
         logger.error(u'获取图片信息失败')
     # 图片src
     medium_src = str(medium.get('src'))
     # 图片路径(格式:主目录/作者/书名标题/书籍大小/图片名称)
     cxt_image_path = '%s/%s' %(self.file_dir, medium_src[medium_src.rfind('/')+1:])
     self.page.img(width=orig.get('width'), height=orig.get('height'), src=cxt_image_path)
     # 添加图片备注
     legend = cxt_data.get('legend')
     legend_type = type(legend)
     if legend_type == unicode:
         self.page.label(str(legend), style='color:#555; font-size:.75em; line-height:1.5;')
     elif legend_type == dict:
         legend_data = legend.get('data')
         legend_data_paragraphs = legend_data.get('paragraphs') # []
         for legend_data_paragraph in legend_data_paragraphs:
             desc_text = self.get_legend_paragraph_text(legend_data_paragraph)
             self.page.label(desc_text, style='color:#555; font-size:.75em; line-height:1.5;')
     elif legend_type == list:
         for legend_data in legend:
             l_type = legend_data.get('type')
             l_data = legend_data.get('data')
             if l_type == 'paragraph':
                 desc_text = str(l_data.get('text'))
                 self.page.label(desc_text, style='color:#555; font-size:.75em; line-height:1.5;')
             else:
                 logger.unknown(u'未知的内容:%s, 类型:%s' %(str(l_data), str(l_type)))
     self.page.div.close()
     return medium_src
Пример #2
0
 def get_head_or_para_text(self, cxt_data_text):
     # 单条内容,直接返回
     if isinstance(cxt_data_text, list) == False:
         return str(cxt_data_text)
     # 多条内容,带注释
     plaintexts = []
     for text in cxt_data_text:
         kind = str(text.get('kind'))
         # 获取内容字符串
         content = self.get_head_or_para_text(text.get('content'))
         if kind == 'plaintext':
             plaintexts.append(content)
         elif kind == 'footnote':
             plaintexts.append('<font style="color:#333; font-size:13px;">[注:%s]</font>' %content)
         elif kind == 'emphasize':
             plaintexts.append('<font style="font-weight:bold;">%s</font>' %content)
         elif kind == 'code':
             plaintexts.append('<font style="%s">%s</font>' %(self.style_code, content))
         elif kind == 'latex':
             plaintexts.append('<font style="color:red;">%s</font>' %content)
         elif kind == 'strikethrough':
             plaintexts.append('<font style="text-decoration: line-through;">%s</font>' %content)
         elif kind == 'regular_script':
             plaintexts.append(content)
         else:
             plaintexts.append(content)
             logger.unknown(u'未知的data->text->kind,text内容:%s,图书标题:%s' %(str(cxt_data_text), self.title))
     return ''.join(plaintexts)
Пример #3
0
 def get_head_or_para_text(self, cxt_data_text):
     # 单条内容,直接返回
     if isinstance(cxt_data_text, list) == False:
         return str(cxt_data_text)
     # 多条内容,带注释
     plaintexts = []
     for text in cxt_data_text:
         kind = str(text.get('kind'))
         # 获取内容字符串
         content = self.get_head_or_para_text(text.get('content'))
         if kind == 'plaintext':
             plaintexts.append(content)
         elif kind == 'footnote':
             plaintexts.append('<font style="color:#333; font-size:13px;">[注:%s]</font>' %content)
         elif kind == 'emphasize':
             plaintexts.append('<font style="font-weight:bold;">%s</font>' %content)
         elif kind == 'code':
             plaintexts.append('<font style="%s">%s</font>' %(self.style_code, content))
         elif kind == 'latex':
             plaintexts.append('<font style="color:red;">%s</font>' %content)
         elif kind == 'strikethrough':
             plaintexts.append('<font style="text-decoration: line-through;">%s</font>' %content)
         elif kind == 'regular_script':
             plaintexts.append(content)
         else:
             plaintexts.append(content)
             logger.unknown(u'未知的data->text->kind,text内容:%s,图书标题:%s' %(str(cxt_data_text), self.title))
     return ''.join(plaintexts)
Пример #4
0
 def get_illus(self, cxt_data):
     self.page.div()  # class_='section'
     # 获取最大图片信息
     orig = cxt_data.get("size").get("orig")
     # 获取中等[medium]图片信息
     medium = self.get_cxt_pic(cxt_data)
     if medium == None:
         logger.error(u"获取图片信息失败")
     # 图片src
     medium_src = str(medium.get("src"))
     # 图片路径(格式:主目录/作者/书名标题/书籍大小/图片名称)
     cxt_image_path = "%s/%s" % (self.file_dir, medium_src[medium_src.rfind("/") + 1 :])
     self.page.img(width=orig.get("width"), height=orig.get("height"), src=cxt_image_path)
     # 添加图片备注
     legend = cxt_data.get("legend")
     legend_type = type(legend)
     if legend_type == unicode:
         self.page.label(str(legend), style="color:#555; font-size:.75em; line-height:1.5;")
     elif legend_type == dict:
         legend_data = legend.get("data")
         legend_data_paragraphs = legend_data.get("paragraphs")  # []
         for legend_data_paragraph in legend_data_paragraphs:
             desc_text = self.get_legend_paragraph_text(legend_data_paragraph)
             self.page.label(desc_text, style="color:#555; font-size:.75em; line-height:1.5;")
     elif legend_type == list:
         for legend_data in legend:
             l_type = legend_data.get("type")
             l_data = legend_data.get("data")
             if l_type == "paragraph":
                 desc_text = str(l_data.get("text"))
                 self.page.label(desc_text, style="color:#555; font-size:.75em; line-height:1.5;")
             else:
                 logger.unknown(u"未知的内容:%s, 类型:%s" % (str(l_data), str(l_type)))
     self.page.div.close()
     return medium_src
Пример #5
0
 def get_post_content(self, contents):
     ## 书籍所有图片远程路径集合
     book_images_remote_path = []
     for cxt in contents:
         cxt_type = cxt.get('type')
         # 具体内容
         cxt_data = cxt.get('data')
         if cxt_type == 'pagebreak':  ## 分页符号
             self.page.p(('', ), class_=gk7.BOOK_PAGE_SPLIT)
             continue
         if cxt_type == 'illus':  ## 图片页
             # 获取图片信息
             illus_remote_src = self.get_illus(cxt_data)
             # 添加至所有图片远程路径集合
             book_images_remote_path.append(illus_remote_src)
             continue
         cxt_data_text = cxt_data.get('text')
         # 为空判断
         if cxt_data_text == '' or len(cxt_data_text) == 0:
             cxt_data_text = '&nbsp;'
         # 内容格式
         cxt_data_format = cxt_data.get('format')
         # 类型判断
         if cxt_type == 'headline':  ## 标题头
             plaintexts = self.get_head_or_para_text(cxt_data_text)
             self.page.h2((plaintexts, ),
                          class_='chapter',
                          style=self.get_text_style(cxt_data_format))
         elif cxt_type == 'paragraph':  ## 段落
             # 获取段落内容
             plaintexts = self.get_head_or_para_text(cxt_data_text)
             # 添加段落至HTML
             self.page.p((plaintexts, ),
                         style=self.get_text_style(cxt_data_format,
                                                   is_indent=True))
         elif cxt_type == 'code':  ## 代码
             self.page.p(style=self.get_text_style(cxt_data_format))
             self.page.code(
                 (str(cxt_data_text).replace('<', '&lt;').replace(
                     '>', '&gt;'), ),
                 style=self.style_code)
             self.page.p.close()
         else:
             logger.unknown(u'未知的内容type,data内容:%s, 书籍名称:%s' %
                            (str(cxt_data), self.title))
     return book_images_remote_path
Пример #6
0
 def create_gallery(self, book_pages):
     book_images_remote_path = []
     # 内容
     for page in book_pages:
         page_type = page.get("type")
         page_data = page.get("data")
         if page_type == "illus":  ## 图片页
             # 获取图片信息
             illus_remote_src = self.get_illus(page_data)
             # 添加至所有图片远程路径集合
             book_images_remote_path.append(illus_remote_src)
         elif page_type == "pagebreak":  ## 分页符号
             pass
         elif page_type == "container":  ## 内容
             paragraphs = page_data.get("paragraphs")
             for paragraph in paragraphs:
                 paragraph_data = paragraph.get("data")
                 paragraph_data_text = paragraph_data.get("text")
                 text_content = ""
                 for text in paragraph_data_text:
                     if type(text) == unicode:
                         text_content += str(text)
                     else:
                         if text:
                             # dict
                             text_content += str(text.get("content"))
                 paragraph_data_format = paragraph_data.get("format")
                 self.page.p((text_content,), style=self.get_text_style(paragraph_data_format))
         else:
             logger.unknown(u"未知的内容type,data内容:%s" % (str(page_data)))
         ## 添加分割页面段落
         self.page.p(("",), class_=gk7.BOOK_PAGE_SPLIT)
     ## 片尾
     self.page.p(
         ("****本书由%s制作,如有问题,请发送邮件至 %s ****" % ("jacksyen", "*****@*****.**"),),
         style="font-size:13px; color:#333;",
     )
     # 写入文件
     filename = self.write_html_to_file()
     return filename, book_images_remote_path
Пример #7
0
 def create_gallery(self, book_pages):
     book_images_remote_path = []
     # 内容
     for page in book_pages:
         page_type = page.get('type')
         page_data = page.get('data')
         if page_type == 'illus':  ## 图片页
             # 获取图片信息
             illus_remote_src = self.get_illus(page_data)
             # 添加至所有图片远程路径集合
             book_images_remote_path.append(illus_remote_src)
         elif page_type == 'pagebreak':  ## 分页符号
             pass
         elif page_type == 'container':  ## 内容
             paragraphs = page_data.get('paragraphs')
             for paragraph in paragraphs:
                 paragraph_data = paragraph.get('data')
                 paragraph_data_text = paragraph_data.get('text')
                 text_content = ''
                 for text in paragraph_data_text:
                     if type(text) == unicode:
                         text_content += str(text)
                     else:
                         if text:
                             # dict
                             text_content += str(text.get('content'))
                 paragraph_data_format = paragraph_data.get('format')
                 self.page.p(
                     (text_content, ),
                     style=self.get_text_style(paragraph_data_format))
         else:
             logger.unknown(u'未知的内容type,data内容:%s' % (str(page_data)))
         ## 添加分割页面段落
         self.page.p(('', ), class_=gk7.BOOK_PAGE_SPLIT)
     ## 片尾
     #self.page.p(('****本书由%s制作,如有问题,请发送邮件至 %s ****' %('jacksyen', '*****@*****.**'), ), style='font-size:13px; color:#333;')
     # 写入文件
     filename = self.write_html_to_file()
     return filename, book_images_remote_path
Пример #8
0
 def get_post_content(self, contents):
     ## 书籍所有图片远程路径集合
     book_images_remote_path = []
     for cxt in contents:
         cxt_type = cxt.get('type')
         # 具体内容
         cxt_data = cxt.get('data')
         if cxt_type == 'pagebreak': ## 分页符号
             self.page.p(('',), class_=gk7.BOOK_PAGE_SPLIT)
             continue
         if cxt_type == 'illus': ## 图片页
             # 获取图片信息
             illus_remote_src = self.get_illus(cxt_data)
             # 添加至所有图片远程路径集合
             book_images_remote_path.append(illus_remote_src)
             continue
         cxt_data_text = cxt_data.get('text')
         # 为空判断
         if cxt_data_text == '' or len(cxt_data_text) == 0:
             cxt_data_text = '&nbsp'
         # 内容格式
         cxt_data_format = cxt_data.get('format')
         # 类型判断
         if cxt_type == 'headline': ## 标题头
             plaintexts = self.get_head_or_para_text(cxt_data_text)
             self.page.h2((plaintexts,), class_='chapter', style=self.get_text_style(cxt_data_format))
         elif cxt_type == 'paragraph': ## 段落
             # 获取段落内容
             plaintexts = self.get_head_or_para_text(cxt_data_text)
             # 添加段落至HTML
             self.page.p((plaintexts,), style=self.get_text_style(cxt_data_format, is_indent=True))
         elif cxt_type == 'code': ## 代码
             self.page.p(style=self.get_text_style(cxt_data_format))
             self.page.code((str(cxt_data_text),), style=self.style_code)
             self.page.p.close()
         else:
             logger.unknown(u'未知的内容type,data内容:%s, 书籍名称:%s' %(str(cxt_data), self.title))
     return book_images_remote_path
Пример #9
0
 def get_post_content(self, contents):
     ## 书籍所有图片远程路径集合
     book_images_remote_path = []
     for cxt in contents:
         cxt_type = cxt.get("type")
         # 具体内容
         cxt_data = cxt.get("data")
         if cxt_type == "pagebreak":  ## 分页符号
             self.page.p(("",), class_=gk7.BOOK_PAGE_SPLIT)
             continue
         if cxt_type == "illus":  ## 图片页
             # 获取图片信息
             illus_remote_src = self.get_illus(cxt_data)
             # 添加至所有图片远程路径集合
             book_images_remote_path.append(illus_remote_src)
             continue
         cxt_data_text = cxt_data.get("text")
         # 为空判断
         if cxt_data_text == "" or len(cxt_data_text) == 0:
             cxt_data_text = "&nbsp"
         # 内容格式
         cxt_data_format = cxt_data.get("format")
         # 类型判断
         if cxt_type == "headline":  ## 标题头
             plaintexts = self.get_head_or_para_text(cxt_data_text)
             self.page.h2((plaintexts,), class_="chapter", style=self.get_text_style(cxt_data_format))
         elif cxt_type == "paragraph":  ## 段落
             # 获取段落内容
             plaintexts = self.get_head_or_para_text(cxt_data_text)
             # 添加段落至HTML
             self.page.p((plaintexts,), style=self.get_text_style(cxt_data_format, is_indent=True))
         elif cxt_type == "code":  ## 代码
             self.page.p(style=self.get_text_style(cxt_data_format))
             self.page.code((str(cxt_data_text),), style=self.style_code)
             self.page.p.close()
         else:
             logger.unknown(u"未知的内容type,data内容:%s, 书籍名称:%s" % (str(cxt_data), self.title))
     return book_images_remote_path
Пример #10
0
 def create_gallery(self, book_pages):
     book_images_remote_path = []
     # 内容
     for page in book_pages:
         page_type = page.get('type')
         page_data = page.get('data')
         if page_type == 'illus':  ## 图片页
             # 获取图片信息
             illus_remote_src = self.get_illus(page_data)
             # 添加至所有图片远程路径集合
             book_images_remote_path.append(illus_remote_src)
         elif page_type == 'pagebreak': ## 分页符号
             pass
         elif page_type == 'container': ## 内容
             paragraphs = page_data.get('paragraphs')
             for paragraph in paragraphs:
                 paragraph_data = paragraph.get('data')
                 paragraph_data_text = paragraph_data.get('text')
                 text_content = ''
                 for text in paragraph_data_text:
                     if type(text) == unicode:
                         text_content += str(text)
                     else:
                         if text:
                             # dict
                             text_content += str(text.get('content'))
                 paragraph_data_format = paragraph_data.get('format')
                 self.page.p((text_content,), style=self.get_text_style(paragraph_data_format))
         else:
             logger.unknown(u'未知的内容type,data内容:%s' %(str(page_data)))
         ## 添加分割页面段落
         self.page.p(('',), class_=gk7.BOOK_PAGE_SPLIT)
     ## 片尾
     self.page.p(('****本书由%s制作,如有问题,请发送邮件至 %s ****' %('jacksyen', '*****@*****.**'), ), style='font-size:13px; color:#333;')
     # 写入文件
     filename = self.write_html_to_file()
     return filename, book_images_remote_path