From 4dcdad39e008fe8083e48143f9c9e06214e73b97 Mon Sep 17 00:00:00 2001 From: Coda Bool Date: Thu, 16 Mar 2023 18:14:15 +0530 Subject: [PATCH] [rds] Adds automation (#86) This is a Python rewrite of the code at #83. Co-authored-by: Nemo Co-authored-by: Marc Wrobel --- src/rds.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/rds.py diff --git a/src/rds.py b/src/rds.py new file mode 100644 index 00000000..0e179c78 --- /dev/null +++ b/src/rds.py @@ -0,0 +1,45 @@ +import re +import urllib.request +from bs4 import BeautifulSoup +from datetime import datetime +import json + +dbs = { + "mysql": "https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/MySQL.Concepts.VersionMgmt.html", + "postgresql": "https://docs.aws.amazon.com/AmazonRDS/latest/PostgreSQLReleaseNotes/postgresql-release-calendar.html", +} + + +def parse_date(d): + return datetime.strptime(d, "%d %B %Y").strftime("%Y-%m-%d") + + +for db, url in dbs.items(): + print(f"::group::{db}") + releases = {} + + with urllib.request.urlopen(url, data=None, timeout=5) as contents: + html = contents.read().decode("utf-8") + soup = BeautifulSoup(html, features="html5lib") + + for table in soup.find_all("table"): + for row in table.find_all("tr"): + columns = row.find_all("td") + + # Must match both the 'Supported XXX minor versions' and + # 'Supported XXX major versions' to have correct release dates + if len(columns) > 3: + r = r"(?P\d+(?:\.\d+)*)" # https://regex101.com/r/BY1vwV/1 + m = re.search(r, columns[0].text.strip(), flags=re.IGNORECASE) + if m: + version = m.group("v") + date = parse_date(columns[2].text.strip()) + print(f"{version} : {date}") + releases[version] = date + + print("::endgroup::") + with open(f"releases/amazon-rds-{db.lower()}.json", "w") as f: + json.dump(dict( + # sort by date then version (desc) + sorted(releases.items(), key=lambda x: (x[1], x[0]), reverse=True) + ), f, indent=2)