[confluence] Refactor script (#218)

Make the script more readable, mostly by:

- using the endoflife.Product class,
- a little bit of renaming and documentation.
This commit is contained in:
Marc Wrobel
2023-12-10 16:45:41 +01:00
committed by GitHub
parent 328ddc3823
commit 2c076ff5f1

View File

@@ -2,27 +2,19 @@ from requests_html import HTMLSession
from common import dates from common import dates
from common import endoflife from common import endoflife
"""Fetch Confluence versions with their dates from the Atlassian Website. """Fetches Confluence versions from www.atlassian.com.
This script is using requests-html (https://requests-html.kennethreitz.org/) Note that requests_html is used because JavaScript is needed to render the page."""
because the page needs JavaScript to render correctly.
"""
PRODUCT = 'confluence' product = endoflife.Product("confluence")
URL = 'https://www.atlassian.com/software/confluence/download-archives' print(f"::group::{product.name}")
r = HTMLSession().get("https://www.atlassian.com/software/confluence/download-archives")
print(f"::group::{PRODUCT}")
session = HTMLSession()
r = session.get(URL)
r.html.render(sleep=1, scrolldown=3) r.html.render(sleep=1, scrolldown=3)
versions = {}
for version_block in r.html.find('.versions-list'): for version_block in r.html.find('.versions-list'):
version = version_block.find('a.product-versions', first=True).attrs['data-version'] version = version_block.find('a.product-versions', first=True).attrs['data-version']
date_text = 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') product.declare_version(version, dates.parse_date(date_text))
print(f"{version}: {date}")
versions[version] = date
endoflife.write_releases(PRODUCT, versions) product.write()
print("::endgroup::") print("::endgroup::")