Quote:
Originally Posted by Capricorn
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