Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Sigil > Plugins

Notices

Reply
 
Thread Tools Search this Thread
Old Yesterday, 05:03 AM   #601
Doitsu
Grand Sorcerer
Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.
 
Doitsu's Avatar
 
Posts: 5,761
Karma: 24088559
Join Date: Dec 2010
Device: Kindle PW2
Quote:
Originally Posted by Capricorn View Post
What tools and websites are good to learn python?
I'd strongly recommend Automate the Boring Stuff with Python by Al Sweigart, which is available for free online.
You'll also need to download the Sigil Framework Guide.
You also might find the Sigil test plugin helpful because it demonstrates most Sigil-specific Python functions.

Here's a minimal proof-of-concept edit plugin that will wrap "the" in all html files in <b> tags:

Code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys, os

# main routine    
def run(bk):
    # iterate over all html files
    for html_id, href in bk.text_iter():
        # read orignal html code from file
        original_html = bk.readfile(html_id)
        # modify html code
        modified_html = original_html.replace('the', '<b>the</b>') 
        if modified_html != original_html:
            # write modified html code to file
            bk.writefile(html_id, modified_html)
            print(os.path.basename(href) + ' updated')
    return 0

def main():
    print('I reached main when I should not have\n')
    return -1

if __name__ == "__main__":
    sys.exit(main())
As you can see it doesn't really require much code. BTW, Sigil comes with a fork of the BeautifulSoup library that makes it really easy to manipulate HTML content. To import it you must use:

Code:
from sigil_bs4 import BeautifulSoup
Doitsu is offline   Reply With Quote
Old Yesterday, 08:04 AM   #602
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 9,062
Karma: 6361556
Join Date: Nov 2009
Device: many
Just to be clear ...

Sigil plugins only allow batch processing of files inside a single loaded epub. If you want to batch process a number of epubs without having to load them in Sigil, python is the way to go but not Sigil Plugins.

That said the python modules in Sigil could be extracted and used in a standalone python program with only low to moderate effort.

Last edited by KevinH; Yesterday at 08:06 AM.
KevinH is offline   Reply With Quote
Advert
Old Yesterday, 01:37 PM   #603
theducks
Well trained by Cats
theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.
 
theducks's Avatar
 
Posts: 31,235
Karma: 60807154
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
Quote:
Originally Posted by DiapDealer View Post
The markup in mobi files was full of small, medium, large, x-small, xx-large, and normal font sizes.

The mobi2xhtml script in the kindleinport plugin has a routine that tried to make some sort of sense out of it:

https://github.com/dougmassay/kindle...2xhtml.py#L358
I made a Sigil Saved Grouped Search that changes those name into ##em (except Normal is just deleted) (I used to have to do a lot of 'cleanup' on older files from the Baen CD's or Free Library.
This is one of the reasons I use Sigil for some tasks and Calibre Editor for others. They fit MY workflow (please keep doing Sigil things, the Sigil way), and Calibre does others.
All we need to do is learn to use the tools we have without making those other folk that want the other way (either editor) use OUR way.
Only if it is broken, does it need fixin'
theducks is offline   Reply With Quote
Old Today, 02:05 AM   #604
Capricorn
Belgian Pommes Frites
Capricorn turned on, tuned in, and dropped out.Capricorn turned on, tuned in, and dropped out.Capricorn turned on, tuned in, and dropped out.Capricorn turned on, tuned in, and dropped out.Capricorn turned on, tuned in, and dropped out.Capricorn turned on, tuned in, and dropped out.Capricorn turned on, tuned in, and dropped out.Capricorn turned on, tuned in, and dropped out.Capricorn turned on, tuned in, and dropped out.Capricorn turned on, tuned in, and dropped out.Capricorn turned on, tuned in, and dropped out.
 
Posts: 131
Karma: 35038
Join Date: Jan 2012
Device: Pocketbook Touch HD
Tools

Quote:
Originally Posted by Doitsu View Post
I'd strongly recommend Automate the Boring Stuff with Python by Al Sweigart, which is available for free online.
You'll also need to download the Sigil Framework Guide.
You also might find the Sigil test plugin helpful because it demonstrates most Sigil-specific Python functions.
Thanks. I will get this book and see where it leads.
Capricorn is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Loading Plugin in development Sladd Development 6 06-17-2014 06:57 PM
Question for plugin development gurus DiapDealer Plugins 2 02-04-2012 11:33 PM
DR800 Plugin development for DR800/DR1000 yuri_b iRex Developer's Corner 0 09-18-2010 09:46 AM
Device plugin development reader42 Plugins 10 03-29-2010 12:39 PM
Calibre plugin development - Newbie problems minstrel Plugins 5 04-12-2009 12:44 PM


All times are GMT -4. The time now is 03:37 AM.


MobileRead.com is a privately owned, operated and funded community.