View Single Post
Old 11-15-2016, 07:29 AM   #5
slowsmile
Witchman
slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.slowsmile ought to be getting tired of karma fortunes by now.
 
Posts: 628
Karma: 788808
Join Date: May 2013
Location: Philippines
Device: Android S5
I've implemented your suggested changes and it didn't work. The problem is the same.

I have this code in a module that contains a worker function:

Code:
try:
    from sigil_bs4 import BeautifulSoup
    print('Sigil bs4 imported')
except:
    from bs4 import BeautifulSoup
    print('regular bs4 imported')


def fixHTML(wdir, file):    
    
    output = wdir + os.sep + 'new_html.htm'
    outfp = open(output, 'wt', encoding=('utf-8'))
    html = open(file, 'rt', encoding='utf-8').read()
    soup = BeautifulSoup(html)
    
    for tag in soup():
        for attribute in ["lang", "id", "dir", "name" "link"]:
            del tag[attribute]    
    |
    More code
    |
    outfp.writelines(str(soup))
    outfp.close()

    os.remove(file)
    os.rename(output, file)
    return(file)
If I set to bundled python in Plugin manager and then hit the OK key and run the plugin, it prints 'Sigil bs4 imported' and it fails. When I deselect the bundled python and set my on system python 3.4 then it prints 'regular bs4 imported' and the plugin successfully removes the attributes from the html file as it should.

My calling is like this:

run()
|
calls
|
convert2Epub --> calls --> fixHTML(contains the sigil_bs4 code above)

I've also already read The Sigil Plugin Framework Guide a while ago. It doesn't really tell you how to use the sigil_bs4 module, it just mentions it. I found out more useful info, including all the code, on FOSSIE and GitHub.

I think I'll try reinstalling Sigil 0.9.7 and see if I can get any joy there.
slowsmile is offline   Reply With Quote