View Single Post
Old 03-07-2023, 05:05 AM   #12
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 8,467
Karma: 5703586
Join Date: Nov 2009
Device: many
Yes, that is what the code Doitsu wrote does. If you do not want to delete pages with img tags and or svg tags then you need to modify that code to check for those tags before deleting.

Something like the following modification to Doitsu's code could be used to detect img and svg tags and prevent deletion if either is found:


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()
        node = soup.body
        if body_text == '' or len(body_text) <= 6:
            if not node.img and not node.svg:
                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: I did NOT test this at all because all I have access to is an ipad.

Last edited by KevinH; 03-07-2023 at 07:04 AM.
KevinH is offline   Reply With Quote