diff options
author | Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org> | 2020-12-27 21:58:47 +0100 |
---|---|---|
committer | Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org> | 2021-01-09 03:14:46 +0100 |
commit | 102cb10bc6a35ca04624b8cd9e52a234778b4f50 (patch) | |
tree | f5afe878ba72c4642ac907a591975c7015e92898 | |
parent | 2ee4f8df327e34a7a213cbe09e444adb32607a9b (diff) | |
download | vendor_replicant-release-scripts-102cb10bc6a35ca04624b8cd9e52a234778b4f50.tar.gz vendor_replicant-release-scripts-102cb10bc6a35ca04624b8cd9e52a234778b4f50.tar.bz2 vendor_replicant-release-scripts-102cb10bc6a35ca04624b8cd9e52a234778b4f50.zip |
release_notes.py: add support for more recent libraries versions
Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
-rwxr-xr-x | release_notes.py | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/release_notes.py b/release_notes.py index 454f384..3c0964b 100755 --- a/release_notes.py +++ b/release_notes.py @@ -23,7 +23,17 @@ from bs4 import BeautifulSoup from html2text import config, HTML2Text -from html2text.utils import wrapwrite + +try: + # This has been removed in more recent + # versions of python-html2text. See commit + # b361467894fb277563b4547ec9d4df49f5e0c6e3 + # (b361467 Remove support for Python ≤ 3.4) + # in https://github.com/Alir3z4/html2text.git + from html2text.utils import wrapwrite +except: + pass + import sys def usage(progname): @@ -36,7 +46,20 @@ if len(sys.argv) != 2: html_file_path = sys.argv[1] with open(html_file_path) as html_file: - soup = BeautifulSoup(html_file, features="lxml").article + try: + soup = BeautifulSoup(html_file, features="html5lib").article + except: + try: + # For some reason the lxml parser isn't found with + # python-beautifulsoup4 4.9.3-3.0 on Parabola. It's + # probably better to use an html5 parser anyway as the + # Replicant blog (now?) uses the html doctype and the + # theme seems to include an html5.js file for the IE 9 + # browser. + soup = BeautifulSoup(html_file, features="lxml").article + except: + print("Cannot find html5lib or lxml parsers") + sys.exit(1) # Format the output to be compatible with mail conventions but make sure that # the links are not split between two lines @@ -46,4 +69,7 @@ config.WRAP_LIST_ITEMS = True config.BODY_WIDTH = 70 parser = HTML2Text() -wrapwrite(parser.handle(soup.decode())) +try: + wrapwrite(parser.handle(soup.decode())) +except: + sys.stdout.write(parser.handle(soup.decode())) |