Ejemplo n.º 1
0
    def test_open(self):
        test_path = os.path.join(os.path.dirname(__file__), self.epub_path)
        book = epub.open(test_path)

        self.assertEqual(book.opf_path, 'OEBPS/content.opf')
        self.assertEqual(book.content_path, 'OEBPS')
        self.assertEqual(book.opf.metadata.languages, ['en'])
        self.assertEqual(book.opf.metadata.titles, [('Testing Epub', '')])
        self.assertEqual(len(book.opf.manifest), 7)

        for key, item in book.opf.manifest.items():
            self.assertEqual(item.identifier, key)
            self.assertIsInstance(item, epub.opf.ManifestItem)

        with epub.open(test_path) as with_book:
            self.assertEqual(with_book.opf.metadata.languages, ['en'])
            self.assertEqual(with_book.opf.metadata.titles,
                             [('Testing Epub', '')])
            self.assertEqual(len(with_book.opf.manifest), 7)
            for key, item in with_book.opf.manifest.items():
                self.assertEqual(item.identifier, key)
                self.assertIsInstance(item, epub.opf.ManifestItem)
Ejemplo n.º 2
0
    def test_open(self):
        working_copy_filename = os.path.join(os.path.dirname(__file__),
                                             self.epub_path)

        # test that the file is correctly open in [a]ppend mode.
        book = epub.open(working_copy_filename, 'w')
        self.assertEqual(book.opf_path, 'OEBPS/content.opf')
        self.assertEqual(book.content_path, 'OEBPS')
        self.assertEqual(book.opf.metadata.languages, [])
        self.assertEqual(book.opf.metadata.titles, [])
        self.assertEqual(len(book.opf.manifest), 1)
        # 1 meta file: mimetype
        # 0 content file
        self.assertEqual(len(book.namelist()), 1)

        self._subtest_add_item(book)
        book.close()
Ejemplo n.º 3
0
    def test_open(self):
        working_copy_filename = os.path.join(os.path.dirname(__file__),
                                             self.epub_path)

        # test that the file is correctly open in [a]ppend mode.
        book = epub.open(working_copy_filename, 'a')
        self.assertEqual(book.opf_path, 'OEBPS/content.opf')
        self.assertEqual(book.content_path, 'OEBPS')
        self.assertEqual(book.opf.metadata.languages, ['fr'])
        self.assertEqual(book.opf.metadata.titles, [('Il était une fois...', '')])
        self.assertEqual(len(book.opf.manifest), 2)
        # 4 meta files: mimetype, container.xml, content.opf, toc.ncx,
        # 1 content file: Section0001.xhtml
        self.assertEqual(len(book.namelist()), 5)

        self._subtest_add_item(book)
        book.close()
Ejemplo n.º 4
0
#!/usr/bin/python3
# -*- coding: utf-8 -*-

import epub
import pickle
from pprint import pprint
from lxml import etree
import re

# tree = etree.parse('examples/feed.xml',encoding='utf8')


book = epub.open("data/K_te_dikt.epub")
txt = []

try:
    for iii, item in enumerate(book.opf.manifest.values()):
        # read the content
        data = book.read_item(item)

        tree = etree.fromstring(data)
        # pprint(data)
        # pprint(tree)
        for t in tree.iterchildren():
            dikt = ""
            for u in t.iterchildren():
                if u.text is not None:
                    if u.text != "Kåte Dikt":
                        dikt += u.text + "\n"
            txt.append(dikt)
Ejemplo n.º 5
0
 def setUp(self):
     self.epub_file = epub.open(self.epub_path)
     if not os.path.exists(self.extracted_dir):
         os.mkdir(self.extracted_dir)
Ejemplo n.º 6
0
 def __init__(self, filename):
     self._book = epub.open(filename)
Ejemplo n.º 7
0
#!/usr/bin/python3
# -*- coding: utf-8 -*-

import epub
import pickle
from pprint import pprint
from lxml import etree
import re
#tree = etree.parse('examples/feed.xml',encoding='utf8')


book=epub.open('data/K_te_dikt.epub')
txt=[]

try:
    for iii,item in enumerate(book.opf.manifest.values()):
        # read the content
        data = book.read_item(item)

        tree=etree.fromstring(data)
            #pprint(data)
            #pprint(tree)
        for t in tree.iterchildren():
            dikt=''
            for u in t.iterchildren():
                if u.text is not None:
                    if u.text!='Kåte Dikt':
                        dikt+=u.text+'\n'
            txt.append(dikt)

except Exception as e: