[visualstudio] Refactor script (#253)

Make the script more readable, mostly by:

- using the Product class,
- a little bit of renaming and documentation.
This commit is contained in:
Marc Wrobel
2023-12-12 07:44:29 +01:00
parent a3232df484
commit d596f3e717

View File

@@ -1,11 +1,8 @@
import re
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
from common import http from common import http
from common import dates from common import dates
from common import endoflife from common import endoflife
PRODUCT = "visualstudio"
# There is no build history for versions 2015 and below. # There is no build history for versions 2015 and below.
# This is not a big deal because there was no version for those release in a very long time. # This is not a big deal because there was no version for those release in a very long time.
URLS = [ URLS = [
@@ -14,11 +11,11 @@ URLS = [
"https://learn.microsoft.com/en-us/visualstudio/releases/2022/release-history", "https://learn.microsoft.com/en-us/visualstudio/releases/2022/release-history",
] ]
print(f"::group::{PRODUCT}") product = endoflife.Product("visualstudio")
versions = {} print(f"::group::{product.name}")
for response in http.fetch_urls(URLS): for response in http.fetch_urls(URLS):
soup = BeautifulSoup(response.text, features="html5lib") soup = BeautifulSoup(response.text, features="html5lib")
for table in soup.find_all("table"): for table in soup.find_all("table"):
headers = [th.get_text().strip().lower() for th in table.find_all("th")] headers = [th.get_text().strip().lower() for th in table.find_all("th")]
if "version" not in headers or "release date" not in headers: if "version" not in headers or "release date" not in headers:
@@ -33,12 +30,10 @@ for response in http.fetch_urls(URLS):
version = cells[version_index].get_text().strip() version = cells[version_index].get_text().strip()
date = cells[date_index].get_text().strip() date = cells[date_index].get_text().strip()
date = dates.parse_date(date).strftime("%Y-%m-%d") date = dates.parse_date(date)
if date and version and re.match(endoflife.DEFAULT_VERSION_REGEX, version): if date and version and endoflife.DEFAULT_VERSION_PATTERN.match(version):
versions[version] = date product.declare_version(version, date)
print(f"{version}: {date}")
product.write()
endoflife.write_releases(PRODUCT, versions)
print("::endgroup::") print("::endgroup::")