Example #1
0
def scan_folder_of_chapters(book_folder, output_folder):
    '''Given a folder look for text/txt files.
        The name should be of the form,

        e.g.
          chapter 01 - In the begining.txt
          chapter 02 - A little bit later.text

        and also some cover art
          cover.jpg

    '''

    book = Epub()
    book.output_folder = output_folder

    # extract book title and author form folder name
    title_author = book_folder[6:].split('-')
    if len(title_author) < 2:
        print "Warning: '%s' isn't for the form 'title - author'," +\
            " will skip this folder"
        return False

    book.title = title_author[0].strip()
    book.primary_author = "-".join(title_author[1:]).strip()

    chapters = []

    # file list, sorted
    filelist = glob("%s/*.*" % book_folder)
    filelist.sort(key=natural_number_sorting)

    for chapter in filelist:

        matched = re.match(u'.*\.[tT][xX][tT]$|.*\.[tT][eE][xX][tT]$', chapter)

        if matched:

            title = chapter.replace("%s/" % book_folder, '')
            title = "-".join(title.split('-')[1:])
            title = title.replace('.text', '')
            title = title.replace('.txt', '')

            chapters.append((title, open(chapter, 'r').read()))

    book.chapters = chapters

    # add an image file
    for image_name in ('jpg', 'JPG', 'jpeg', 'JPEG', 'Jpeg', 'Jpg'):
        image_name = '%s/cover.%s' % (book_folder, image_name)
        if path.exists(image_name):
            book.cover_art = image_name
            break
    else:
        print 'Warning: The cover art file, "%s/cover.jpg", wasn\'t found' %\
                                                                    book_folder
        book.cover_art = None

    book.save()

    return True
Example #2
0
def scan_folder_of_chapters(book_folder, output_folder):
    '''Given a folder look for text/txt files.
        The name should be of the form,

        e.g.
          chapter 01 - In the begining.txt
          chapter 02 - A little bit later.text

        and also some cover art
          cover.jpg

    '''

    book = Epub()
    book.output_folder = output_folder

    # extract book title and author form folder name
    title_author = book_folder[6:].split('-')
    if len(title_author) < 2:
        print "Warning: '%s' isn't for the form 'title - author'," +\
            " will skip this folder"
        return False

    book.title = title_author[0].strip()
    book.primary_author = "-".join(title_author[1:]).strip()

    chapters = []

    # file list, sorted
    filelist = glob("%s/*.*" % book_folder)
    filelist.sort(key=natural_number_sorting)

    for chapter in filelist:

        matched = re.match(u'.*\.[tT][xX][tT]$|.*\.[tT][eE][xX][tT]$', chapter)

        if matched:

            title = chapter.replace("%s/" % book_folder, '')
            title = "-".join(title.split('-')[1:])
            title = title.replace('.text', '')
            title = title.replace('.txt', '')

            chapters.append((title, open(chapter, 'r').read()))

    book.chapters = chapters

    # add an image file
    for image_name in ('jpg', 'JPG', 'jpeg', 'JPEG', 'Jpeg', 'Jpg'):
        image_name = '%s/cover.%s' % (book_folder, image_name)
        if path.exists(image_name):
            book.cover_art = image_name
            break
    else:
        print 'Warning: The cover art file, "%s/cover.jpg", wasn\'t found' %\
                                                                    book_folder
        book.cover_art = None

    book.save()

    return True
Example #3
0
        text = '''<b>Bold</b> short blob of text.
        <i>Italic</i> an so on.
        Another line of text, but a little longer and so on.

        Multiline gaps will be ignored.
        To create a newline, use the "<br>" tag.
        <br>
        <br>
        Line further down.
        <blockquote>Some text</blockquote>
        '''

        chapter_2 = ('Formatting', text)

        book = Epub()

        book.isbn = '0743421922'
        book.primary_author = 'Banks, Iain M.'
        book.title = 'Look to windward'
        book.cover_art = 'test/cover.jpg'

        book.chapters = [
            ('Prologue', 'Some content ...'),
            ('The Light of Ancient Mistakes', 'more content...\n<i>etc</i>'),
            ('Winter Storm',
             'Lots of text\nAnother <b>line</b>...\nthird line\nfourth line')
        ]

        book.save()
Example #4
0
        text = '''<b>Bold</b> short blob of text.
        <i>Italic</i> an so on.
        Another line of text, but a little longer and so on.

        Multiline gaps will be ignored.
        To create a newline, use the "<br>" tag.
        <br>
        <br>
        Line further down.
        <blockquote>Some text</blockquote>
        '''

        chapter_2 = ('Formatting', text)

        book = Epub()

        book.isbn = '0743421922'
        book.primary_author = 'Banks, Iain M.'
        book.title = 'Look to windward'
        book.cover_art = 'test/cover.jpg'

        book.chapters = [('Prologue', 'Some content ...'),
                         ('The Light of Ancient Mistakes',
                          'more content...\n<i>etc</i>'),
                         ('Winter Storm',
              'Lots of text\nAnother <b>line</b>...\nthird line\nfourth line')]

        book.save()

    ##