From 6c5c84206e719a1f2c8d07f0b098c7668d86b8a6 Mon Sep 17 00:00:00 2001 From: Marc Wrobel Date: Tue, 12 Dec 2023 07:41:30 +0100 Subject: [PATCH] [rhel] Refactor script (#245) Make the script more readable, mostly by: - using the Product class, - a little bit of renaming and documentation. --- src/rhel.py | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/rhel.py b/src/rhel.py index 07f0950e..443a1c88 100644 --- a/src/rhel.py +++ b/src/rhel.py @@ -1,30 +1,30 @@ import re from bs4 import BeautifulSoup -from common import http +from common import dates from common import endoflife +from common import http -URL = "https://access.redhat.com/articles/3078" # https://regex101.com/r/877ibq/1 -regex = r"RHEL (?P\d)(\. ?(?P\d+))?(( Update (?P\d))| GA)?" +VERSION_PATTERN = re.compile(r"RHEL (?P\d)(\. ?(?P\d+))?(( Update (?P\d))| GA)?") -print("::group::rhel") -response = http.fetch_url(URL) +product = endoflife.Product("redhat") +print(f"::group::{product.name}") +response = http.fetch_url("https://access.redhat.com/articles/3078") soup = BeautifulSoup(response.text, features="html5lib") -versions = {} for tr in soup.findAll("tr"): td_list = tr.findAll("td") - if len(td_list) > 0: - version = td_list[0].get_text() - m = re.match(regex, version.strip()).groupdict() - version = m["major"] - if m["minor"]: - version += ".%s" % m["minor"] - if m["minor2"]: - version += ".%s" % m["minor2"] - date = td_list[1].get_text() - versions[version] = date - print(f"{version}: {date}") + if len(td_list) == 0: + continue -endoflife.write_releases('redhat', versions) + version_str = td_list[0].get_text().strip() + version_match = VERSION_PATTERN.match(version_str).groupdict() + version = version_match["major"] + version += ("." + version_match["minor"]) if version_match["minor"] else "" + version += ("." + version_match["minor2"]) if version_match["minor2"] else "" + date = dates.parse_date(td_list[1].get_text()) + + product.declare_version(version, date) + +product.write() print("::endgroup::")