Quote:
Originally Posted by Gergely
FileNotFoundError: [Errno 2] No such file or directory: 'Text/9781118087220cover.xhtml'
|
You can't use
open() in plugins. You'll need to use
bk.readfile(id) instead. For example, the following minimal code 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())