Ejemplo n.º 1
0
 def build_indexpage(self):
     Li_Templete = "<li><a href='%s'>%s</a>"
     menu = []
     for art in self.articles:
         li = Li_Templete % (art[1] + '.html', art[0])
         menu.append(li)
     index_name = self.root + os.sep.join(
         ['epub', self.filename, 'OEBPS', 'html', 'index.html'])
     HB.build_file(index_name, HB.INDEX_TEMPLATE, ''.join(menu))
Ejemplo n.º 2
0
 def build_infopage(self):
     info_name = self.root + os.sep.join([
                 'epub', 
                 self.filename, 
                 'OEBPS', 
                 'html', 
                 'infoPage.html'
                 ])
     HB.build_file(info_name, HB.INFOPAGE_TEMPLATE)
Ejemplo n.º 3
0
 def build_indexpage(self):
     Li_Templete = "<li><a href='%s'>%s</a>"
     menu = []
     for art in self.articles:
         li = Li_Templete % (art[1]+'.html', art[0])
         menu.append(li)
     index_name = self.root + os.sep.join([
                 'epub', 
                 self.filename, 
                 'OEBPS', 
                 'html', 
                 'index.html'
                 ])
     HB.build_file(index_name, HB.INDEX_TEMPLATE, ''.join(menu))
Ejemplo n.º 4
0
    def process_json(self):
        with open(self.root + 'articles.json', 'r') as json_file:
            for art in json_file:
                art_dict = json.loads(art)
                '''
                    keys in art_dict:
                    [u'origin',
                     u'author',
                     u'title',
                     u'image_urls',
                     u'content',
                     u'date',
                     u'tag',
                     u'en_title',
                     u'images']
                '''
                # save image names
                if 'image_urls' in art_dict:
                    for imname in art_dict['image_urls']:
                        self.image_names.add(imname)

                # save article name
                for t in ('title', 'en_title', 'tag', 'date'):
                    if not t in art_dict:
                        art_dict[t] = ""
                self.articles.append((art_dict[u'title'], 
                    art_dict[u'en_title'], 
                    art_dict[u'tag'],
                    art_dict[u'date']))

                # build article html
                article_file_name = self.root + os.sep.join([
                    'epub', 
                    self.filename, 
                    'OEBPS', 
                    'html', 
                    art_dict[u'en_title']+'.html'
                    ])
                HB.build_file(article_file_name, HB.ARTICLE_TEMPLATE, 
                    art_dict[u'title'],
                    art_dict[u'title'],
                    art_dict[u'author'],
                    art_dict[u'date'],
                    art_dict[u'tag'],
                    art_dict[u'content'])
Ejemplo n.º 5
0
    def process_json(self):
        with open(self.root + 'articles.json', 'r') as json_file:
            for art in json_file:
                art_dict = json.loads(art)
                '''
                    keys in art_dict:
                    [u'origin',
                     u'author',
                     u'title',
                     u'image_urls',
                     u'content',
                     u'date',
                     u'tag',
                     u'en_title',
                     u'images']
                '''
                # save image names
                if 'image_urls' in art_dict:
                    for imname in art_dict['image_urls']:
                        self.image_names.add(imname)

                # save article name
                for t in ('title', 'en_title', 'tag', 'date'):
                    if not t in art_dict:
                        art_dict[t] = ""
                self.articles.append(
                    (art_dict[u'title'], art_dict[u'en_title'],
                     art_dict[u'tag'], art_dict[u'date']))

                # build article html
                article_file_name = self.root + os.sep.join([
                    'epub', self.filename, 'OEBPS', 'html',
                    art_dict[u'en_title'] + '.html'
                ])
                HB.build_file(article_file_name, HB.ARTICLE_TEMPLATE,
                              art_dict[u'title'], art_dict[u'title'],
                              art_dict[u'author'], art_dict[u'date'],
                              art_dict[u'tag'], art_dict[u'content'])
Ejemplo n.º 6
0
 def build_infopage(self):
     info_name = self.root + os.sep.join(
         ['epub', self.filename, 'OEBPS', 'html', 'infoPage.html'])
     HB.build_file(info_name, HB.INFOPAGE_TEMPLATE)