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:
self.ignore_lts = ignore_lts
self.ignore_interim = ignore_interim
@property
def row_list(self) -> list:
def get_table_rows(self, only_data: bool = True):
"""
:param only_data: to check you want to ignore the table header
"""
# get requests
res = requests.get(self.path_url)
# check requests status code
......@@ -38,37 +41,42 @@ class UbuntuRelease:
raise Exception(f"Error requests - status: {status}")
# get all table rows
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
row = []
row_list = []
# get table_rows without header
for val in table_rows[8:]:
for val in self.get_table_rows():
val = val.strip()
if val:
if 'Ubuntu ' not in val:
row.append(val.replace("/", ""))
else:
row.append(val)
row_list.append(row)
row = []
return row_list
@property
def get_list_version(self) -> dict:
data = {"latest": [], "lts": []}
for row in self.row_list:
if len(row) == 2:
if not row[0].split(".")[0].isnumeric():
continue
if 'LTS' in row[1]:
name = row[1].split("(")[1].replace(")", "")
short = name.split()[0].lower()
data['lts'].append((row[0], short, name))
typology = "LTS"
else:
typology = "interim"
name = row[1].split("(")[1].replace(")", "")
short = name.split()[0].lower()
data['latest'].append((row[0], short, name))
return data
row_list.append((row[0], short, name, typology))
row = []
# the lambda is just out of scruple
return sorted(row_list, key=lambda x: x[0], reverse=True)
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