diff --git a/src/ros.py b/src/ros.py index a4bb87bb..7f0d754b 100644 --- a/src/ros.py +++ b/src/ros.py @@ -1,37 +1,33 @@ -import datetime import re from bs4 import BeautifulSoup -from common import http +from common import dates from common import endoflife +from common import http -URL = "https://wiki.ros.org/Distributions" # https://regex101.com/r/c1ribd/1 -regex = r"^ROS (?P(\w| )+)" +VERSION_PATTERN = re.compile(r"^ROS (?P(\w| )+)") -print("::group::ros") -response = http.fetch_url(URL) +product = endoflife.Product("ros") +print(f"::group::{product.name}") +response = http.fetch_url("https://wiki.ros.org/Distributions") soup = BeautifulSoup(response.text, features="html5lib") -versions = {} for tr in soup.findAll("tr"): td_list = tr.findAll("td") - if len(td_list) > 0: - version = td_list[0].get_text() + if len(td_list) == 0: + continue - m = re.match(regex, version.strip()) - if m: - version = td_list[0].findAll("a")[0]["href"][1:] - try: - date = datetime.datetime.strptime( - td_list[1].get_text().strip(), "%B %d, %Y" - ) - # The date is a suffix (May 23rd, 2020) - except ValueError: - x = td_list[1].get_text().split(",") - date = datetime.datetime.strptime(x[0][:-2] + x[1], "%B %d %Y") - abs_date = date.strftime("%Y-%m-%d") - versions[version] = abs_date - print(f"{version}: {abs_date}") + version_str = td_list[0].get_text().strip() + if VERSION_PATTERN.match(version_str): + # Get the "code" (such as noetic) instead of the display name (such as Noetic Ninjemys) + version = td_list[0].findAll("a")[0]["href"][1:] + try: + date = dates.parse_date(td_list[1].get_text()) + except ValueError: # The day has a suffix (such as May 23rd, 2020) + x = td_list[1].get_text().split(",") + date = dates.parse_date(x[0][:-2] + x[1]) -endoflife.write_releases('ros', versions) + product.declare_version(version, date) + +product.write() print("::endgroup::")