View Single Post
Old 12-26-2019, 04:22 AM   #33
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,738
Karma: 24031403
Join Date: Dec 2010
Device: Kindle PW2
Quote:
Originally Posted by najgori View Post
...or make simple program (in python): open file no. 1, read line, change whatever you want, write line in file no. 2. repeat untill the end.
If you already know basic Python commands, you might as well create an ad-hoc Sigil plugin. The following minimal plugin.py code demonstrates how to use replace() to replace the with <b>the</b> and re.sub() to replace <i>...</i> with <em>...</em>.

PHP Code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sysosre

# main routine    
def run(bk):
    
# iterate over all html files
    
for html_idhref 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>'
        
modified_html re.sub(r'(</*)i>'r'\1em>'modified_html )
        if 
modified_html != original_html:
            
# write modified html code to file
            
bk.writefile(html_idmodified_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()) 
Doitsu is offline