From d190da8073efe013753efbf03d3cd9f017f931bf Mon Sep 17 00:00:00 2001 From: Marc Wrobel Date: Thu, 11 Sep 2025 12:21:20 +0200 Subject: [PATCH] [discourse] Add auto method (#515) Closes #505. --- src/common/dates.py | 1 + src/discourse.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 src/discourse.py diff --git a/src/common/dates.py b/src/common/dates.py index 16109ce9..91aeceaf 100644 --- a/src/common/dates.py +++ b/src/common/dates.py @@ -58,6 +58,7 @@ def parse_datetime(text: str, formats: list[str] = frozenset([ "%a %d %b %Y %H:%M:%S %z", # Wed 01 Jan 2020 00:00:00 -0400 "%a %b %d %H:%M:%S %Z %Y", # Wed Jan 01 00:00:00 UTC 2020 "%a %b %d %H:%M:%S %z %Y", # Wed Jan 01 00:00:00 -0400 2020 + "%b %d %Y %I:%M %p", # Jan 1 2020 0:00 pm "%Y%m%d%H%M%S", # 20230501083234 ]), to_utc: bool = True) -> datetime: """Parse a given text representing a datetime using a list of formats, diff --git a/src/discourse.py b/src/discourse.py new file mode 100644 index 00000000..3d5fffda --- /dev/null +++ b/src/discourse.py @@ -0,0 +1,30 @@ +import logging +import re + +from bs4 import BeautifulSoup +from common import dates, http +from common.releasedata import ProductData, config_from_argv + +"""Fetch versions from a discourse server.""" + +config = config_from_argv() +with ProductData(config.product) as product_data: + html = BeautifulSoup(http.fetch_javascript_url(config.url)) + + for topic in html.select("tr.topic-list-item"): + title = topic.select_one("span.link-top-line").get_text(strip=True) + versions = config.first_match(title) + if not versions: + logging.debug("Skipping %s: does not match regex", title) + continue + + name = config.render(versions) + print(topic) + date_str = topic.select_one("td.activity").get("title").strip() + date_match = re.search(r"Created:\s*([A-Za-z]+\s+\d{1,2},\s+\d{4}\s+\d{1,2}:\d{2}\s+[ap]m)", date_str) + if not date_match: + logging.debug("Skipping %s: no created date found", title) + continue + + date = dates.parse_datetime(date_match.group(1)) + product_data.declare_version(name, date)