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:
24
src/gke.py
24
src/gke.py
@@ -13,18 +13,16 @@ URL_BY_PRODUCT = {
|
||||
}
|
||||
|
||||
for product_name, url in URL_BY_PRODUCT.items():
|
||||
product = releasedata.Product(product_name)
|
||||
relnotes = http.fetch_url(url)
|
||||
relnotes_soup = BeautifulSoup(relnotes.text, features="html5lib")
|
||||
with releasedata.ProductData(product_name) as product_data:
|
||||
relnotes = http.fetch_url(url)
|
||||
relnotes_soup = BeautifulSoup(relnotes.text, features="html5lib")
|
||||
|
||||
for section in relnotes_soup.find_all('section', class_='releases'):
|
||||
for h2 in section.find_all('h2'): # h2 contains the date
|
||||
date = dates.parse_date(h2.get('data-text'))
|
||||
for section in relnotes_soup.find_all('section', class_='releases'):
|
||||
for h2 in section.find_all('h2'): # h2 contains the date
|
||||
date = dates.parse_date(h2.get('data-text'))
|
||||
|
||||
next_div = h2.find_next('div') # The div next to the h2 contains the notes about changes made on that date
|
||||
for li in next_div.find_all('li'):
|
||||
if "versions are now available" in li.text:
|
||||
for version in VERSION_PATTERN.findall(li.find('ul').text):
|
||||
product.declare_version(version, date)
|
||||
|
||||
product.write()
|
||||
next_div = h2.find_next('div') # The div next to the h2 contains the notes about changes made on that date
|
||||
for li in next_div.find_all('li'):
|
||||
if "versions are now available" in li.text:
|
||||
for version in VERSION_PATTERN.findall(li.find('ul').text):
|
||||
product_data.declare_version(version, date)
|
||||
|
||||
Reference in New Issue
Block a user