View Single Post
Old 02-15-2023, 04:43 PM   #7
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,748
Karma: 24032915
Join Date: Dec 2010
Device: Kindle PW2
Quote:
Originally Posted by LostOnTheLine View Post
I'm also trying to work out a way to do something I was already told on here wasn't possible, remove blank pages. So far I've yet to succeed, but with this I feel like I'm a lot closer than anything before has ever been.
That requires only minimal code changes to Becky's plugin:
Spoiler:
Code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from sigil_bs4 import BeautifulSoup

def run(bk):
    for html_id, href in bk.text_iter():
        html = bk.readfile(html_id)
        soup = BeautifulSoup(html, 'html.parser')
        body_text = soup.body.text.strip()
        if body_text == '' or len(body_text) <= 6:
            print('INFO: Removing {}... '.format(href))
            bk.deletefile(html_id)
    print('\nPlease click OK to close the Plugin Runner window.')
    return 0

def main():
    print("I reached main when I should not have\n")
    return -1

if __name__ == "__main__":
    sys.exit(main())

Please note that the plugin will crash Sigil if you use it with an epub that only contains blank pages.
Doitsu is offline   Reply With Quote