[amazon-neptune] Refactor script (#211)

Make the script more readable, partly by making use of the new endoflife.Product class.
This commit is contained in:
Marc Wrobel
2023-12-10 09:42:19 +01:00
committed by GitHub
parent 6e32738794
commit 06c462c3cc

View File

@@ -1,31 +1,26 @@
import re import re
import xml.dom.minidom
from common import http from common import http
from common import dates from common import dates
from common import endoflife from common import endoflife
from xml.dom.minidom import parseString
"""Fetch versions with their dates from the RSS feed of """Fetches Amazon Neptune versions from its RSS feed on docs.aws.amazon.com."""
https://docs.aws.amazon.com/neptune/latest/userguide/engine-releases.html.
"""
PRODUCT = "amazon-neptune" RSS_URL = "https://docs.aws.amazon.com/neptune/latest/userguide/rssupdates.rss"
REGEX = r"^Engine version (?P<version>[0-9R.]+)$" VERSION_REGEX = re.compile(r"^Engine version (?P<version>[0-9R.]+)$")
URL = "https://docs.aws.amazon.com/neptune/latest/userguide/rssupdates.rss"
print(f"::group::{PRODUCT}") product = endoflife.Product("amazon-neptune")
versions = {} 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) for entry in rss.getElementsByTagName("item"):
rss = parseString(response.text) version_str = entry.getElementsByTagName("title")[0].firstChild.nodeValue
for item in rss.getElementsByTagName("item"): date_str = entry.getElementsByTagName("pubDate")[0].firstChild.nodeValue
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}")
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::") print("::endgroup::")