From 06c462c3cce336d59ae8b30bcaeb374173e7509a Mon Sep 17 00:00:00 2001 From: Marc Wrobel Date: Sun, 10 Dec 2023 09:42:19 +0100 Subject: [PATCH] [amazon-neptune] Refactor script (#211) Make the script more readable, partly by making use of the new endoflife.Product class. --- src/amazon-neptune.py | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/src/amazon-neptune.py b/src/amazon-neptune.py index 5c2276e0..30be8848 100644 --- a/src/amazon-neptune.py +++ b/src/amazon-neptune.py @@ -1,31 +1,26 @@ import re +import xml.dom.minidom from common import http from common import dates from common import endoflife -from xml.dom.minidom import parseString -"""Fetch versions with their dates from the RSS feed of -https://docs.aws.amazon.com/neptune/latest/userguide/engine-releases.html. -""" +"""Fetches Amazon Neptune versions from its RSS feed on docs.aws.amazon.com.""" -PRODUCT = "amazon-neptune" -REGEX = r"^Engine version (?P[0-9R.]+)$" -URL = "https://docs.aws.amazon.com/neptune/latest/userguide/rssupdates.rss" +RSS_URL = "https://docs.aws.amazon.com/neptune/latest/userguide/rssupdates.rss" +VERSION_REGEX = re.compile(r"^Engine version (?P[0-9R.]+)$") -print(f"::group::{PRODUCT}") -versions = {} +product = endoflife.Product("amazon-neptune") +print(f"::group::{product.name}") +rss_response = http.fetch_url(RSS_URL) +rss = xml.dom.minidom.parseString(rss_response.text) -response = http.fetch_url(URL) -rss = parseString(response.text) -for item in rss.getElementsByTagName("item"): - title = item.getElementsByTagName("title")[0].firstChild.nodeValue - pubDate = item.getElementsByTagName("pubDate")[0].firstChild.nodeValue - matches = re.match(REGEX, title) - if matches: - version = matches['version'] - date = dates.parse_datetime(pubDate).strftime("%Y-%m-%d") - versions[version] = date - print(f"{version}: {date}") +for entry in rss.getElementsByTagName("item"): + version_str = entry.getElementsByTagName("title")[0].firstChild.nodeValue + date_str = entry.getElementsByTagName("pubDate")[0].firstChild.nodeValue -endoflife.write_releases(PRODUCT, versions) + version_match = VERSION_REGEX.match(version_str) + if version_match: + product.declare_version(version_match['version'], dates.parse_datetime(date_str)) + +product.write() print("::endgroup::")