Simplify date parsing (#195)

Create common functions parse_date, parse_month_year_date and parse_datetime.

Those functions support trying multiple formats, and come with default formats lists that support most of the date format encountered so far.

Notable change: year-month dates are now set to the end of month (impacted couchbase-server and ibm-aix).
This commit is contained in:
Marc Wrobel
2023-11-26 21:01:35 +01:00
committed by GitHub
parent 1e65a048b0
commit 0d17306872
24 changed files with 133 additions and 168 deletions

View File

@@ -1,7 +1,7 @@
import re
from bs4 import BeautifulSoup
from common import dates
from common import endoflife
from datetime import datetime
PRODUCT = "splunk"
URL = "https://docs.splunk.com/Documentation/Splunk"
@@ -9,10 +9,6 @@ RELNOTES_URL_TEMPLATE = "https://docs.splunk.com/Documentation/Splunk/{version}/
PATTERN = r"Splunk Enterprise (?P<version>\d+\.\d+(?:\.\d+)*) was (?:first )?released on (?P<date>\w+\s\d\d?,\s\d{4})\."
def convert_date(date: str) -> str:
return datetime.strptime(date, "%B %d, %Y").strftime("%Y-%m-%d")
def get_latest_minor_versions(versions):
versions_split = [version.split('.') for version in versions]
@@ -55,7 +51,7 @@ latest_minor_versions_urls = [RELNOTES_URL_TEMPLATE.format(version=v) for v in l
for response in endoflife.fetch_urls(latest_minor_versions_urls):
for (version, date_str) in re.findall(PATTERN, response.text, re.MULTILINE):
version = f"{version}.0" if len(version.split(".")) == 2 else version # convert x.y to x.y.0
date = convert_date(date_str)
date = dates.parse_date(date_str).strftime("%Y-%m-%d")
versions[version] = date
print(f"{version}: {date}")