[oracle-jdk] Refactor script (#237)
Make the script more readable, mostly by: - using the Product class, - removing the use of functions when unnecessary, - a little bit of renaming and documentation.
This commit is contained in:
@@ -1,46 +1,26 @@
|
||||
from requests_html import HTMLSession
|
||||
from common import dates
|
||||
from common import endoflife
|
||||
|
||||
"""Fetch Java versions with their dates from https://www.java.com/releases/.
|
||||
"""Fetch Java versions from https://www.java.com/releases/.
|
||||
|
||||
This script is using requests-html (https://requests-html.kennethreitz.org/)
|
||||
because https://www.java.com/releases/ needs JavaScript to render correctly.
|
||||
This script is using requests-html because the page needs JavaScript to render correctly."""
|
||||
|
||||
requests-html is using pyppeteer internally for executing javascript. And
|
||||
pyppeteer is relying on Chromium, which is automatically downloaded in
|
||||
~/.local/share/pyppeteer by the library. This path can be overridden by
|
||||
declaring a PYPPETEER_HOME environment variable. Unfortunately exporting this
|
||||
variable in the python script does not work, so it has to be done before this
|
||||
script execution.
|
||||
"""
|
||||
product = endoflife.Product("oracle-jdk")
|
||||
print(f"::group::{product.name}")
|
||||
r = HTMLSession().get('https://www.java.com/releases/')
|
||||
r.html.render(sleep=1, scrolldown=3)
|
||||
|
||||
PRODUCT = "oracle-jdk"
|
||||
URL = "https://www.java.com/releases/"
|
||||
previous_date = None
|
||||
for row in r.html.find('#released tr'):
|
||||
version_cell = row.find('td.anchor', first=True)
|
||||
if version_cell:
|
||||
version = version_cell.attrs['id']
|
||||
date_str = row.find('td')[1].text
|
||||
date = dates.parse_date(date_str) if date_str else previous_date
|
||||
product.declare_version(version, date)
|
||||
previous_date = date
|
||||
|
||||
|
||||
def fetch_releases():
|
||||
session = HTMLSession()
|
||||
r = session.get('https://www.java.com/releases/')
|
||||
r.html.render(sleep=1, scrolldown=3)
|
||||
|
||||
releases = {}
|
||||
previous_date = None
|
||||
for row in r.html.find('#released tr'):
|
||||
version_cell = row.find('td.anchor', first=True)
|
||||
|
||||
if version_cell:
|
||||
version = version_cell.attrs['id']
|
||||
date = row.find('td')[1].text
|
||||
date = previous_date if not date else date
|
||||
print(f"{version}: {date}")
|
||||
releases[version] = date
|
||||
previous_date = date
|
||||
|
||||
return releases
|
||||
|
||||
|
||||
print(f"::group::{PRODUCT}")
|
||||
all_versions = fetch_releases()
|
||||
all_versions.pop('1.0_alpha') # only version we don't want, regex not needed
|
||||
endoflife.write_releases(PRODUCT, all_versions)
|
||||
product.remove_version('1.0_alpha') # the only version we don't want, a regex is not needed
|
||||
product.write()
|
||||
print("::endgroup::")
|
||||
|
||||
Reference in New Issue
Block a user