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:
36
src/ros.py
36
src/ros.py
@@ -6,25 +6,23 @@ from common import dates, http, releasedata
|
||||
# https://regex101.com/r/c1ribd/1
|
||||
VERSION_PATTERN = re.compile(r"^ROS (?P<name>(\w| )+)")
|
||||
|
||||
product = releasedata.Product("ros")
|
||||
response = http.fetch_url("https://wiki.ros.org/Distributions")
|
||||
soup = BeautifulSoup(response.text, features="html5lib")
|
||||
with releasedata.ProductData("ros") as product_data:
|
||||
response = http.fetch_url("https://wiki.ros.org/Distributions")
|
||||
soup = BeautifulSoup(response.text, features="html5lib")
|
||||
|
||||
for tr in soup.findAll("tr"):
|
||||
td_list = tr.findAll("td")
|
||||
if len(td_list) == 0:
|
||||
continue
|
||||
for tr in soup.findAll("tr"):
|
||||
td_list = tr.findAll("td")
|
||||
if len(td_list) == 0:
|
||||
continue
|
||||
|
||||
version_str = td_list[0].get_text().strip()
|
||||
if VERSION_PATTERN.match(version_str):
|
||||
# Get the "code" (such as noetic) instead of the display name (such as Noetic Ninjemys)
|
||||
version = td_list[0].findAll("a")[0]["href"][1:]
|
||||
try:
|
||||
date = dates.parse_date(td_list[1].get_text())
|
||||
except ValueError: # The day has a suffix (such as May 23rd, 2020)
|
||||
x = td_list[1].get_text().split(",")
|
||||
date = dates.parse_date(x[0][:-2] + x[1])
|
||||
version_str = td_list[0].get_text().strip()
|
||||
if VERSION_PATTERN.match(version_str):
|
||||
# Get the "code" (such as noetic) instead of the display name (such as Noetic Ninjemys)
|
||||
version = td_list[0].findAll("a")[0]["href"][1:]
|
||||
try:
|
||||
date = dates.parse_date(td_list[1].get_text())
|
||||
except ValueError: # The day has a suffix (such as May 23rd, 2020)
|
||||
x = td_list[1].get_text().split(",")
|
||||
date = dates.parse_date(x[0][:-2] + x[1])
|
||||
|
||||
product.declare_version(version, date)
|
||||
|
||||
product.write()
|
||||
product_data.declare_version(version, date)
|
||||
|
||||
Reference in New Issue
Block a user