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.
23 lines
854 B
Python
23 lines
854 B
Python
import re
|
|
|
|
import mwparserfromhell
|
|
from common import dates, endoflife, http, releasedata
|
|
|
|
DATE_PATTERN = re.compile(r"\d{4}-\d{2}-\d{2}")
|
|
|
|
for config in endoflife.list_configs_from_argv():
|
|
with releasedata.ProductData(config.product) as product_data:
|
|
response = http.fetch_url(config.url)
|
|
wikicode = mwparserfromhell.parse(response.text)
|
|
|
|
for tr in wikicode.ifilter_tags(matches=lambda node: node.tag == "tr"):
|
|
items = tr.contents.filter_tags(matches=lambda node: node.tag == "td")
|
|
if len(items) < 2:
|
|
continue
|
|
|
|
version = items[0].__strip__()
|
|
date_str = items[1].__strip__()
|
|
if config.first_match(version) and DATE_PATTERN.match(date_str):
|
|
date = dates.parse_date(date_str)
|
|
product_data.declare_version(version, date)
|