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:
25
src/php.py
25
src/php.py
@@ -2,18 +2,15 @@ from common import dates, endoflife, http, releasedata
|
||||
|
||||
MAIN_URL = "https://www.php.net/releases/index.php?json&max=-1"
|
||||
|
||||
product = releasedata.Product("php")
|
||||
with releasedata.ProductData("php") as product_data:
|
||||
# Fetch major versions
|
||||
latest_by_major = http.fetch_url(MAIN_URL).json()
|
||||
major_version_urls = [f"{MAIN_URL}&version={major_version}" for major_version in latest_by_major]
|
||||
|
||||
# Fetch major versions
|
||||
latest_by_major = http.fetch_url(MAIN_URL).json()
|
||||
major_version_urls = [f"{MAIN_URL}&version={major_version}" for major_version in latest_by_major]
|
||||
|
||||
# Fetch all versions for major versions
|
||||
for major_versions_response in http.fetch_urls(major_version_urls):
|
||||
major_versions_data = major_versions_response.json()
|
||||
for version in major_versions_data:
|
||||
if endoflife.DEFAULT_VERSION_PATTERN.match(version): # exclude versions such as "3.0.x (latest)"
|
||||
date = dates.parse_date(major_versions_data[version]["date"])
|
||||
product.declare_version(version, date)
|
||||
|
||||
product.write()
|
||||
# Fetch all versions for major versions
|
||||
for major_versions_response in http.fetch_urls(major_version_urls):
|
||||
major_versions_data = major_versions_response.json()
|
||||
for version in major_versions_data:
|
||||
if endoflife.DEFAULT_VERSION_PATTERN.match(version): # exclude versions such as "3.0.x (latest)"
|
||||
date = dates.parse_date(major_versions_data[version]["date"])
|
||||
product_data.declare_version(version, date)
|
||||
|
||||
Reference in New Issue
Block a user