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:
@@ -1,6 +1,6 @@
|
||||
from requests_html import HTMLSession
|
||||
from common import dates
|
||||
from common import endoflife
|
||||
from datetime import datetime
|
||||
|
||||
"""Fetch Confluence versions with their dates from the Atlassian Website.
|
||||
|
||||
@@ -11,13 +11,7 @@ because the page needs JavaScript to render correctly.
|
||||
PRODUCT = 'confluence'
|
||||
URL = 'https://www.atlassian.com/software/confluence/download-archives'
|
||||
|
||||
|
||||
def parse_date(text):
|
||||
return datetime.strptime(text, "%d-%b-%Y").strftime("%Y-%m-%d")
|
||||
|
||||
|
||||
print(f"::group::{PRODUCT}")
|
||||
|
||||
session = HTMLSession()
|
||||
r = session.get(URL)
|
||||
r.html.render(sleep=1, scrolldown=3)
|
||||
@@ -25,7 +19,8 @@ r.html.render(sleep=1, scrolldown=3)
|
||||
versions = {}
|
||||
for version_block in r.html.find('.versions-list'):
|
||||
version = version_block.find('a.product-versions', first=True).attrs['data-version']
|
||||
date = parse_date(version_block.find('.release-date', first=True).text)
|
||||
date_text = version_block.find('.release-date', first=True).text
|
||||
date = dates.parse_date(date_text).strftime('%Y-%m-%d')
|
||||
print(f"{version}: {date}")
|
||||
versions[version] = date
|
||||
|
||||
|
||||
Reference in New Issue
Block a user