[unrealircd] Refactor script (#252)

Make the script more readable, mostly by:

- using the Product class,
- a little bit of renaming and documentation.
This commit is contained in:
Marc Wrobel
2023-12-12 07:50:31 +01:00
committed by GitHub
parent 83792e03a5
commit 0becabcb86

View File

@@ -1,24 +1,26 @@
import mwparserfromhell
import re
from common import http
from common import dates
from common import endoflife
from common import http
URL = "https://www.unrealircd.org/docwiki/index.php?title=History_of_UnrealIRCd_releases&action=raw"
DATE_PATTERN = re.compile(r"\d{4}-\d{2}-\d{2}")
print("::group::unrealircd")
response = http.fetch_url(URL)
product = endoflife.Product("unrealircd")
print(f"::group::{product.name}")
response = http.fetch_url("https://www.unrealircd.org/docwiki/index.php?title=History_of_UnrealIRCd_releases&action=raw")
wikicode = mwparserfromhell.parse(response.text)
versions = {}
for tr in wikicode.ifilter_tags(matches=lambda node: node.tag == "tr"):
items = tr.contents.filter_tags(matches=lambda node: node.tag == "td")
if len(items) >= 2:
maybe_version = items[0].__strip__()
if re.match(endoflife.DEFAULT_VERSION_REGEX, maybe_version):
maybe_date = items[1].__strip__()
if re.match(r"\d{4}-\d{2}-\d{2}", maybe_date):
versions[maybe_version] = maybe_date
print(f"{maybe_version}: {maybe_date}")
if len(items) < 2:
continue
endoflife.write_releases('unrealircd', versions)
version = items[0].__strip__()
date_str = items[1].__strip__()
if endoflife.DEFAULT_VERSION_PATTERN.match(version) and DATE_PATTERN.match(date_str):
date = dates.parse_date(date_str)
product.declare_version(version, date)
product.write()
print("::endgroup::")