Make releasedata.Product usable in 'with' expression (#294)
This way the writing of the JSON file is handled automatically if the update does not fail. It pave the way to further global improvements, such as a better error handling.
This commit is contained in:
@@ -7,22 +7,20 @@ METHOD = 'distrowatch'
|
||||
|
||||
p_filter = sys.argv[1] if len(sys.argv) > 1 else None
|
||||
for product in endoflife.list_products(METHOD, p_filter):
|
||||
product_data = releasedata.Product(product.name)
|
||||
for config in product.get_auto_configs(METHOD):
|
||||
response = http.fetch_url(f"https://distrowatch.com/index.php?distribution={config.url}")
|
||||
soup = BeautifulSoup(response.text, features="html5lib")
|
||||
with releasedata.ProductData(product.name) as product_data:
|
||||
for config in product.get_auto_configs(METHOD):
|
||||
response = http.fetch_url(f"https://distrowatch.com/index.php?distribution={config.url}")
|
||||
soup = BeautifulSoup(response.text, features="html5lib")
|
||||
|
||||
for table in soup.select("td.News1>table.News"):
|
||||
headline = table.select_one("td.NewsHeadline a[href]").get_text().strip()
|
||||
versions_match = config.first_match(headline)
|
||||
if not versions_match:
|
||||
continue
|
||||
for table in soup.select("td.News1>table.News"):
|
||||
headline = table.select_one("td.NewsHeadline a[href]").get_text().strip()
|
||||
versions_match = config.first_match(headline)
|
||||
if not versions_match:
|
||||
continue
|
||||
|
||||
# multiple versions may be released at once (e.g. Ubuntu 16.04.7 and 18.04.5)
|
||||
versions = config.render(versions_match).split("\n")
|
||||
date = dates.parse_date(table.select_one("td.NewsDate").get_text())
|
||||
# multiple versions may be released at once (e.g. Ubuntu 16.04.7 and 18.04.5)
|
||||
versions = config.render(versions_match).split("\n")
|
||||
date = dates.parse_date(table.select_one("td.NewsDate").get_text())
|
||||
|
||||
for version in versions:
|
||||
product_data.declare_version(version, date)
|
||||
|
||||
product_data.write()
|
||||
for version in versions:
|
||||
product_data.declare_version(version, date)
|
||||
|
||||
Reference in New Issue
Block a user