Refactor product releases writing
Create a common function to write resulting JSON files to the releases directory. It makes this task simpler to read and maintain, while making it modifiable at a central point in the future. One example of such modification could be the sorting of the versions in a uniform way for all the scripts.
This commit is contained in:
10
src/ros.py
10
src/ros.py
@@ -1,5 +1,4 @@
|
||||
import datetime
|
||||
import json
|
||||
import re
|
||||
from bs4 import BeautifulSoup
|
||||
from common import endoflife
|
||||
@@ -8,11 +7,11 @@ URL = "https://wiki.ros.org/Distributions"
|
||||
# https://regex101.com/r/c1ribd/1
|
||||
regex = r"^ROS (?P<name>(\w| )+)"
|
||||
|
||||
versions = {}
|
||||
|
||||
print("::group::ros")
|
||||
response = endoflife.fetch_url(URL)
|
||||
soup = BeautifulSoup(response, features="html5lib")
|
||||
|
||||
versions = {}
|
||||
for tr in soup.findAll("tr"):
|
||||
td_list = tr.findAll("td")
|
||||
if len(td_list) > 0:
|
||||
@@ -32,7 +31,6 @@ for tr in soup.findAll("tr"):
|
||||
abs_date = date.strftime("%Y-%m-%d")
|
||||
versions[version] = abs_date
|
||||
print("%s: %s" % (version, abs_date))
|
||||
print("::endgroup::")
|
||||
|
||||
with open("releases/ros.json", "w") as f:
|
||||
f.write(json.dumps(versions, indent=2))
|
||||
endoflife.write_releases('ros', versions)
|
||||
print("::endgroup::")
|
||||
|
||||
Reference in New Issue
Block a user