Files
endoflife-date-release-data/src/lua.py
Marc Wrobel f404274310 Align custom scripts with generic scripts (#445)
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.
2025-06-07 17:25:05 +02:00

26 lines
1.2 KiB
Python

import re
from bs4 import BeautifulSoup
from common import dates, endoflife, http, releasedata
"""Fetches Lua releases from lua.org."""
RELEASED_AT_PATTERN = re.compile(r"Lua\s*(?P<release>\d+\.\d+)\s*was\s*released\s*on\s*(?P<release_date>\d+\s*\w+\s*\d{4})")
VERSION_PATTERN = re.compile(r"(?P<version>\d+\.\d+\.\d+),\s*released\s*on\s*(?P<version_date>\d+\s*\w+\s*\d{4})")
for config in endoflife.list_configs_from_argv():
with releasedata.ProductData(config.product) as product_data:
page = http.fetch_url(config.url)
soup = BeautifulSoup(page.text, 'html.parser')
page_text = soup.text # HTML is broken, no way to parse it with beautifulsoup
for release_match in RELEASED_AT_PATTERN.finditer(page_text):
release = release_match.group('release')
release_date = dates.parse_date(release_match.group('release_date'))
product_data.get_release(release).set_release_date(release_date)
for version_match in VERSION_PATTERN.finditer(page_text):
version = version_match.group('version')
version_date = dates.parse_date(version_match.group('version_date'))
product_data.declare_version(version, version_date)