[version_table] Add auto method (#514)

Similar to release_table, but for versions.
This commit is contained in:
Marc Wrobel
2025-09-10 17:39:28 +02:00
parent 91788dcca3
commit 20b0c8d1ff
3 changed files with 77 additions and 6 deletions

View File

@@ -13,9 +13,9 @@ from liquid import Template
This script works based on a definition provided in the product's frontmatter to locate the table and extract the
necessary information. Available configuration options are:
- selector (mandatory, no default): A CSS selector used to locate one or more tables in the page.
- header_selector (mandatory, default = thead tr): A CSS selector used to locate the table's header row.
- rows_selector (mandatory, default = tbody tr): A CSS selector used to locate the table's rows.
- selector (optional, default = table): A CSS selector used to locate one or more tables in the page.
- header_selector (optional, default = thead tr): A CSS selector used to locate the table's header row.
- rows_selector (optional, default = tbody tr): A CSS selector used to locate the table's rows.
- user_agent (optional, default = <endoflife.date-bot User-Agent>): A user agent string to use when fetching the page.
Unused when render_javascript is true.
- render_javascript (optional, default = false): A boolean value indicating whether to render JavaScript on the page.
@@ -61,7 +61,6 @@ fields:
Supported CSS selectors are defined by BeautifulSoup and documented on its website. For more information, see
https://beautiful-soup-4.readthedocs.io/en/latest/index.html?highlight=selector#css-selectors."""
METHOD = "release_table"
SUPPORTED_TYPES = ["date", "string", "range", "identifier"]
STRING_TYPES = ["string", "identifier"]
STRING_FIELDS = ["releaseCycle", "releaseLabel"]
@@ -160,15 +159,19 @@ class Field:
config = config_from_argv()
with ProductData(config.product) as product_data:
user_agent: str = config.data.get("user_agent", http.ENDOFLIFE_BOT_USER_AGENT)
render_js: bool = config.data.get("render_javascript", False)
render_js_wait_until: str | None = config.data.get("render_javascript_wait_until", None)
render_js_wait_for: str | None = config.data.get("render_javascript_wait_for", None)
render_js_click_selector: str | None = config.data.get("render_javascript_click_selector", None)
header_row_selector: str = config.data.get("header_selector", "thead tr")
remove_if_undefined_field: str | None = config.data.get("remove_if_undefined", None)
table_selector: str = config.data.get("selector", "table")
rows_selector: str = config.data.get("rows_selector", "tbody tr")
cells_selector: str = "td, th"
remove_if_undefined_field: str | None = config.data.get("remove_if_undefined", None)
release_cycle_field = Field("releaseCycle", config.data["fields"].pop("releaseCycle"))
fields = [Field(name, definition) for name, definition in config.data["fields"].items()]
@@ -179,7 +182,7 @@ with ProductData(config.product) as product_data:
response_text = http.fetch_url(config.url, user_agent=user_agent).text
soup = BeautifulSoup(response_text, features="html5lib")
for table in soup.select(config.data["selector"]):
for table in soup.select(table_selector):
header_row = table.select_one(header_row_selector)
if not header_row:
logging.info(f"skipping table with attributes {table.attrs}: no header row found")