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:
@@ -10,25 +10,23 @@ from common import dates, http, releasedata
|
||||
ANNOUNCEMENT_PATTERN = re.compile(r"includes\s+the\s+following\s+changes", re.IGNORECASE)
|
||||
VERSION_PATTERN = re.compile(r"Looker\s+(?P<version>\d+\.\d+)", re.IGNORECASE)
|
||||
|
||||
product = releasedata.Product("looker")
|
||||
response = http.fetch_url("https://cloud.google.com/feeds/looker-release-notes.xml")
|
||||
rss = xml.dom.minidom.parseString(response.text)
|
||||
with releasedata.ProductData("looker") as product_data:
|
||||
response = http.fetch_url("https://cloud.google.com/feeds/looker-release-notes.xml")
|
||||
rss = xml.dom.minidom.parseString(response.text)
|
||||
|
||||
for item in rss.getElementsByTagName("entry"):
|
||||
content = item.getElementsByTagName("content")[0].firstChild.nodeValue
|
||||
content_soup = BeautifulSoup(content, features="html5lib")
|
||||
for item in rss.getElementsByTagName("entry"):
|
||||
content = item.getElementsByTagName("content")[0].firstChild.nodeValue
|
||||
content_soup = BeautifulSoup(content, features="html5lib")
|
||||
|
||||
announcement_match = content_soup.find(string=ANNOUNCEMENT_PATTERN)
|
||||
if not announcement_match:
|
||||
continue
|
||||
announcement_match = content_soup.find(string=ANNOUNCEMENT_PATTERN)
|
||||
if not announcement_match:
|
||||
continue
|
||||
|
||||
version_match = VERSION_PATTERN.search(announcement_match.parent.get_text())
|
||||
if not version_match:
|
||||
continue
|
||||
version_match = VERSION_PATTERN.search(announcement_match.parent.get_text())
|
||||
if not version_match:
|
||||
continue
|
||||
|
||||
version = version_match.group("version")
|
||||
date_str = item.getElementsByTagName("updated")[0].firstChild.nodeValue
|
||||
date = dates.parse_datetime(date_str)
|
||||
product.declare_version(version, date)
|
||||
|
||||
product.write()
|
||||
version = version_match.group("version")
|
||||
date_str = item.getElementsByTagName("updated")[0].firstChild.nodeValue
|
||||
date = dates.parse_datetime(date_str)
|
||||
product_data.declare_version(version, date)
|
||||
|
||||
Reference in New Issue
Block a user