Align custom scripts with generic scripts, making them configurable. This has a few advantages: - script code is more unified, - no more hard-coded method names in scripts, which is less error prone and make it easier to rename scripts, - no more hard coded product names in scripts, which is less error prone and make it easier to rename products, - less hard-coded URLs and regexes in scripts, which makes auto-configuration more expressive / updatable, Also added method `endoflife.list_configs_from_argv()` so that it is easier to manipulate scripts arguments.
24 lines
1.0 KiB
Python
24 lines
1.0 KiB
Python
from bs4 import BeautifulSoup
|
|
from common import dates, endoflife, http, releasedata
|
|
|
|
"""Fetch Java versions from https://www.java.com/releases/.
|
|
|
|
This script is using requests-html because the page needs JavaScript to render correctly."""
|
|
|
|
for config in endoflife.list_configs_from_argv():
|
|
with releasedata.ProductData(config.product) as product_data:
|
|
content = http.fetch_javascript_url(config.url, wait_until='networkidle')
|
|
soup = BeautifulSoup(content, 'html.parser')
|
|
|
|
previous_date = None
|
|
for row in soup.select('#released tr'):
|
|
version_cell = row.select_one('td.anchor')
|
|
if version_cell:
|
|
version = version_cell.attrs['id']
|
|
date_str = row.select('td')[1].text
|
|
date = dates.parse_date(date_str) if date_str else previous_date
|
|
product_data.declare_version(version, date)
|
|
previous_date = date
|
|
|
|
product_data.remove_version('1.0_alpha') # the only version we don't want, a regex is not needed
|