[aws-lambda] Refactor script (#215)
Make the script more readable, mostly by: - using the endoflife.Product class, - removing the unnecessary use of functions, - a little bit of renaming.
This commit is contained in:
@@ -3,56 +3,48 @@ from common import http
|
||||
from common import endoflife
|
||||
from datetime import datetime
|
||||
|
||||
"""Fetch new AWS lambda runtimes from https://docs.aws.amazon.com.
|
||||
"""Fetches AWS lambda runtimes from https://docs.aws.amazon.com.
|
||||
|
||||
This script does not retrieve release dates, as they are only available
|
||||
in release announcements. Instead, it uses the release dates from the
|
||||
endoflife.date product file. This has the advantage of being warned
|
||||
about new releases, without having releaseDate information (wrongly)
|
||||
updated.
|
||||
This script does not retrieve release dates, as they are only available in release announcements.
|
||||
Instead, it uses the release dates from the endoflife.date product file. This has the advantage of
|
||||
being warned about new releases, without having releaseDate information (wrongly) updated.
|
||||
|
||||
If one day release dates are available in the AWS documentation, it would
|
||||
be better to make use them though. Note that this would also be unnecessary
|
||||
if it was possible to disable release / latest release dates updates in the
|
||||
latest.py script.
|
||||
"""
|
||||
|
||||
PRODUCT = 'aws-lambda'
|
||||
URL = 'https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html'
|
||||
If one day release dates are available in the AWS documentation, it would be better to make use
|
||||
them though. Note that this would also be unnecessary if it was possible to disable release/latest
|
||||
release dates updates in the latest.py script."""
|
||||
|
||||
|
||||
def fetch_product_file_release_date(releaseCycle, product):
|
||||
if 'releases' in product.keys():
|
||||
for release in product['releases']:
|
||||
def get_release_data(product):
|
||||
try:
|
||||
return endoflife.load_product(product.name)
|
||||
except FileNotFoundError:
|
||||
print(f"{product.name} file not found, real release dates will not be used.")
|
||||
return {}
|
||||
|
||||
|
||||
def release_date(releaseCycle, releases_data):
|
||||
if 'releases' in releases_data.keys():
|
||||
for release in releases_data['releases']:
|
||||
if releaseCycle == release['releaseCycle']:
|
||||
return release['releaseDate'].strftime("%Y-%m-%d")
|
||||
return release['releaseDate']
|
||||
|
||||
return datetime.now().strftime("%Y-%m-%d")
|
||||
return datetime.now()
|
||||
|
||||
|
||||
print(f"::group::{PRODUCT}")
|
||||
releases_data = {}
|
||||
try:
|
||||
releases_data = endoflife.load_product(PRODUCT)
|
||||
except FileNotFoundError:
|
||||
releases_data = {}
|
||||
print(f"{PRODUCT} file not found, real release dates will not be used.")
|
||||
|
||||
versions = {}
|
||||
response = http.fetch_url(URL)
|
||||
product = endoflife.Product("aws-lambda")
|
||||
print(f"::group::{product.name}")
|
||||
releases_data = get_release_data(product)
|
||||
response = http.fetch_url("https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html")
|
||||
soup = BeautifulSoup(response.text, features="html5lib")
|
||||
|
||||
for row in soup.find_all("tr"):
|
||||
cells = row.find_all("td")
|
||||
if len(cells) == 6: # Supported Runtimes
|
||||
identifier = cells[1].get_text().strip()
|
||||
elif len(cells) == 5: # Unsupported Runtimes
|
||||
identifier = cells[1].get_text().strip()
|
||||
else: # Header rows
|
||||
if len(cells) != 6 and len(cells) != 5: # 6 = Supported Runtimes, 5 = Unsupported Runtimes
|
||||
continue
|
||||
|
||||
date = fetch_product_file_release_date(identifier, releases_data)
|
||||
versions[identifier] = date
|
||||
print(f"{identifier}: {date}")
|
||||
identifier = cells[1].get_text().strip()
|
||||
date = release_date(identifier, releases_data)
|
||||
product.declare_version(identifier, date)
|
||||
|
||||
endoflife.write_releases(PRODUCT, versions)
|
||||
product.write()
|
||||
print("::endgroup::")
|
||||
|
||||
Reference in New Issue
Block a user