retronews

a featureful fork of the luke8086/retronews hn+lobste.rs tui
Log | Files | Refs | README | LICENSE

commit 7fb108f63445e48a679a73967c3ef0471bbb0929
parent 6d10c1a3f54c7d68c53b79ed93b0ec7bc6722c42
Author: quantumish <freifeld.david@gmail.com>
Date:   Sun,  9 Aug 2026 16:50:44 -0700

Remove html.unescape and re.fullmatch uses to support python 3.2

Diffstat:
Mretronews.py | 18+++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/retronews.py b/retronews.py @@ -135,6 +135,7 @@ LB_URL_REX = re.compile(r"^https://lobste\.rs/s/([a-z0-9]{6}).*$") TRUNCATE = lambda s,l: s[:l] + class ExitException(Exception): def __init__(self, code = 0, message = ""): self.code = code @@ -988,7 +989,7 @@ def hn_parse_search_hit(hit): content_location="https://news.ycombinator.com/item?id={}".format(hit['objectID']), date=datetime.fromtimestamp(hit["created_at_i"]), author=hit["author"], - title=html.unescape(hit["title"]), + title=html_unescape(hit["title"]), total_comments=(hit["num_comments"] or 0) + 1 ) @@ -996,7 +997,7 @@ def hn_parse_search_hit(hit): def hn_parse_entry(entry, thread_id = "", parent = None): thread_id = thread_id or str(entry["id"]) - my_title = html.unescape(entry["title"]) if entry["title"] else None + my_title = html_unescape(entry["title"]) if entry["title"] else None parent_title = parent.title if parent else "" parent_title = parent_title if parent_title.startswith("Re: ") else "Re: {}".format(parent_title) @@ -1068,6 +1069,16 @@ def datetime_from_iso(iso): iso = iso.replace(":", "") return datetime.strptime(iso, "%Y-%m-%dT%H%M%S.%f%z") +def html_unescape(string, mapping={}): + # gross hack exploiting how python only evaluates the default argument once + if len(mapping) == 0: + print("requesting...") + req = urllib.request.Request("https://html.spec.whatwg.org/entities.json") + resp = urllib.request.urlopen(req).read().decode() + mapping.update(json.loads(resp)) + for replacement in mapping: + string = string.replace(replacement, mapping[replacement]["characters"]) + return string def lb_parse_thread(thread): comments = {} @@ -1455,7 +1466,8 @@ def app_render_pager_line(app, row, line): app.screen.move(row, 0) for part in text_split_urls(line): - is_url = URL_REX.fullmatch(part) + re_match = URL_REX.match(part) + is_url = re_match.end() == len(part) if re_match is not None else False part_attr = app.colors["url"] if is_url and hl_urls else line_attr app.screen.addstr(part, part_attr)