View Single Post
Old 10-19-2025, 06: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,763
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