[looker] Refactor script (#233)

Make the script more readable, mostly by:

- using the Product classes,
- a little bit of renaming and documentation.
This commit is contained in:
Marc Wrobel
2023-12-10 22:34:06 +01:00
committed by GitHub
parent 72402edafb
commit 5ba19940ec

View File

@@ -1,36 +1,37 @@
import re
import xml.dom.minidom
from bs4 import BeautifulSoup
from common import http
from common import dates
from common import endoflife
from xml.dom.minidom import parseString
"""Fetch Looker versions with their dates from the Google Cloud release notes RSS feed.
"""Fetch Looker versions from the Google Cloud release notes RSS feed.
"""
PRODUCT = "looker"
URL = "https://cloud.google.com/feeds/looker-release-notes.xml"
ANNOUNCEMENT_PATTERN = re.compile(r"includes\s+the\s+following\s+changes", re.IGNORECASE)
VERSION_PATTERN = re.compile(r"Looker\s+(?P<version>\d+\.\d+)", re.IGNORECASE)
product = endoflife.Product("looker")
print(f"::group::{product.name}")
response = http.fetch_url("https://cloud.google.com/feeds/looker-release-notes.xml")
rss = xml.dom.minidom.parseString(response.text)
print(f"::group::{PRODUCT}")
versions = {}
response = http.fetch_url(URL)
rss = parseString(response.text)
for item in rss.getElementsByTagName("entry"):
date = dates.parse_datetime(item.getElementsByTagName("updated")[0].firstChild.nodeValue).strftime("%Y-%m-%d")
content = item.getElementsByTagName("content")[0].firstChild.nodeValue
soup = BeautifulSoup(content, features="html5lib")
content_soup = BeautifulSoup(content, features="html5lib")
announcement = soup.find(string=ANNOUNCEMENT_PATTERN)
if announcement:
m = re.search(VERSION_PATTERN, announcement.parent.get_text())
if m:
version = m.group("version")
versions[version] = date
print(f"{version}: {date}")
announcement_match = content_soup.find(string=ANNOUNCEMENT_PATTERN)
if not announcement_match:
continue
endoflife.write_releases(PRODUCT, versions)
version_match = VERSION_PATTERN.search(announcement_match.parent.get_text())
if not version_match:
continue
version = version_match.group("version")
date_str = item.getElementsByTagName("updated")[0].firstChild.nodeValue
date = dates.parse_datetime(date_str)
product.declare_version(version, date)
product.write()
print("::endgroup::")