diff options
author | Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org> | 2021-04-26 16:42:25 +0200 |
---|---|---|
committer | Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org> | 2021-04-26 19:27:18 +0200 |
commit | 11150894031d0d4135cf7e94b5701491e75f0d51 (patch) | |
tree | f93529b5aaddcbd3b64e08ac98a5526a6ed0a210 | |
parent | 30f05f09a79b473e47e33d03e958553976616a0b (diff) | |
download | vendor_replicant-release-scripts-11150894031d0d4135cf7e94b5701491e75f0d51.tar.gz vendor_replicant-release-scripts-11150894031d0d4135cf7e94b5701491e75f0d51.tar.bz2 vendor_replicant-release-scripts-11150894031d0d4135cf7e94b5701491e75f0d51.zip |
release_notes: cleanup the code
Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
-rwxr-xr-x | release_notes.py | 67 |
1 files changed, 39 insertions, 28 deletions
diff --git a/release_notes.py b/release_notes.py index 3c0964b..95ae737 100755 --- a/release_notes.py +++ b/release_notes.py @@ -40,36 +40,47 @@ def usage(progname): print("{} path/to/file.html".format(progname)) sys.exit(1) -if len(sys.argv) != 2: - usage(sys.argv[0]) +def convert(html_file_path): + with open(html_file_path) as html_file: + 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 + config.INLINE_LINKS = False + config.PROTECT_LINKS = True + config.WRAP_LIST_ITEMS = True + config.BODY_WIDTH = 70 + + parser = HTML2Text() + text = parser.handle(soup.decode()) + + return text + +def main(): + if len(sys.argv) != 2: + usage(sys.argv[0]) -html_file_path = sys.argv[1] + html_file_path = sys.argv[1] + + text = convert(html_file_path) -with open(html_file_path) as html_file: try: - soup = BeautifulSoup(html_file, features="html5lib").article + wrapwrite(text) 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) + sys.stdout.write(text) -# Format the output to be compatible with mail conventions but make sure that -# the links are not split between two lines -config.INLINE_LINKS = False -config.PROTECT_LINKS = True -config.WRAP_LIST_ITEMS = True -config.BODY_WIDTH = 70 - -parser = HTML2Text() -try: - wrapwrite(parser.handle(soup.decode())) -except: - sys.stdout.write(parser.handle(soup.decode())) +if __name__ == '__main__': + main() |