Commit 02b48162 authored by shadMod's avatar shadMod 💬

rename row_list() with get_table_rows() to get all table rows

now get_list_version() return sort list
parent b1eee15e
...@@ -28,8 +28,11 @@ class UbuntuRelease: ...@@ -28,8 +28,11 @@ class UbuntuRelease:
self.ignore_lts = ignore_lts self.ignore_lts = ignore_lts
self.ignore_interim = ignore_interim self.ignore_interim = ignore_interim
@property def get_table_rows(self, only_data: bool = True):
def row_list(self) -> list: """
:param only_data: to check you want to ignore the table header
"""
# get requests # get requests
res = requests.get(self.path_url) res = requests.get(self.path_url)
# check requests status code # check requests status code
...@@ -38,37 +41,42 @@ class UbuntuRelease: ...@@ -38,37 +41,42 @@ class UbuntuRelease:
raise Exception(f"Error requests - status: {status}") raise Exception(f"Error requests - status: {status}")
# get all table rows # get all table rows
table_rows = html.fromstring(res.content).xpath('//pre//text()') table_rows = html.fromstring(res.content).xpath('//pre//text()')
# if only_data is True ignore table header
if only_data is True:
return table_rows[8:]
# else get all table
return table_rows
@property
def get_list_version(self) -> list:
# init clean row and row_list # init clean row and row_list
row = [] row = []
row_list = [] row_list = []
# get table_rows without header # get table_rows without header
for val in table_rows[8:]: for val in self.get_table_rows():
val = val.strip() val = val.strip()
if val: if val:
if 'Ubuntu ' not in val: if 'Ubuntu ' not in val:
row.append(val.replace("/", "")) row.append(val.replace("/", ""))
else: else:
row.append(val) row.append(val)
row_list.append(row)
row = []
return row_list
@property if len(row) == 2:
def get_list_version(self) -> dict:
data = {"latest": [], "lts": []}
for row in self.row_list:
if not row[0].split(".")[0].isnumeric(): if not row[0].split(".")[0].isnumeric():
continue continue
if 'LTS' in row[1]: if 'LTS' in row[1]:
name = row[1].split("(")[1].replace(")", "") typology = "LTS"
short = name.split()[0].lower()
data['lts'].append((row[0], short, name))
else: else:
typology = "interim"
name = row[1].split("(")[1].replace(")", "") name = row[1].split("(")[1].replace(")", "")
short = name.split()[0].lower() short = name.split()[0].lower()
data['latest'].append((row[0], short, name)) row_list.append((row[0], short, name, typology))
return data row = []
# the lambda is just out of scruple
return sorted(row_list, key=lambda x: x[0], reverse=True)
class CompileVersion: class CompileVersion:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment