aboutsummaryrefslogtreecommitdiffstats
path: root/release_notes.py
blob: 454f3849da49c6d9ea8814b591c82e5de8c67b80 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env python3
# encoding: utf-8
# Copyright (C) 2020 Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.

# How to use:
# - Download the release notes from Wordpress. If it's not published yet you
#   can still click on preview and save-as the page
# - Point this program to the resulting html file, it will generate a text
#   version of it.

from bs4 import BeautifulSoup
from html2text import config, HTML2Text
from html2text.utils import wrapwrite
import sys

def usage(progname):
    print("{} path/to/file.html".format(progname))
    sys.exit(1)

if len(sys.argv) != 2:
    usage(sys.argv[0])

html_file_path = sys.argv[1]

with open(html_file_path) as html_file:
    soup = BeautifulSoup(html_file, features="lxml").article

# 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()
wrapwrite(parser.handle(soup.decode()))