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:
@@ -5,19 +5,18 @@ from requests_html import HTMLSession
|
||||
|
||||
This script is using requests-html because the page needs JavaScript to render correctly."""
|
||||
|
||||
product = releasedata.Product("oracle-jdk")
|
||||
r = HTMLSession().get('https://www.java.com/releases/')
|
||||
r.html.render(sleep=1, scrolldown=3)
|
||||
with releasedata.ProductData("oracle-jdk") as product_data:
|
||||
r = HTMLSession().get('https://www.java.com/releases/')
|
||||
r.html.render(sleep=1, scrolldown=3)
|
||||
|
||||
previous_date = None
|
||||
for row in r.html.find('#released tr'):
|
||||
version_cell = row.find('td.anchor', first=True)
|
||||
if version_cell:
|
||||
version = version_cell.attrs['id']
|
||||
date_str = row.find('td')[1].text
|
||||
date = dates.parse_date(date_str) if date_str else previous_date
|
||||
product.declare_version(version, date)
|
||||
previous_date = date
|
||||
previous_date = None
|
||||
for row in r.html.find('#released tr'):
|
||||
version_cell = row.find('td.anchor', first=True)
|
||||
if version_cell:
|
||||
version = version_cell.attrs['id']
|
||||
date_str = row.find('td')[1].text
|
||||
date = dates.parse_date(date_str) if date_str else previous_date
|
||||
product_data.declare_version(version, date)
|
||||
previous_date = date
|
||||
|
||||
product.remove_version('1.0_alpha') # the only version we don't want, a regex is not needed
|
||||
product.write()
|
||||
product_data.remove_version('1.0_alpha') # the only version we don't want, a regex is not needed
|
||||
|
||||
Reference in New Issue
Block a user