From 515cd6d8da6a806ee4d5d830affb5aa7b2aed973 Mon Sep 17 00:00:00 2001 From: Yann Herklotz Date: Thu, 30 May 2019 16:16:31 +0100 Subject: Fix the conversion --- scripts/convert.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) mode change 100644 => 100755 scripts/convert.py (limited to 'scripts') diff --git a/scripts/convert.py b/scripts/convert.py old mode 100644 new mode 100755 index e179774..a1e68ca --- a/scripts/convert.py +++ b/scripts/convert.py @@ -3,19 +3,29 @@ import sys from bs4 import BeautifulSoup import csv +import re def main(file_): with open(file_, "r") as f: file_contents = f.read() - soup = BeautifulSoup(file_contents) + sec = re.compile(r"([0-9.]+)s") + + soup = BeautifulSoup(file_contents, "html.parser") table = soup.select_one("table") - headers = [th.text.encode("utf-8") for th in table.select("tr th")] + headers = [th.text for th in table.select("tr th")] + vals = [[td.text for td in row.find_all("td")] for row in table.select("tr + tr")][:-2] + + headers = map(lambda x: "Size" if x == "Size (loc)" else x, headers) + + vals = map(lambda l: map(lambda s: sec.sub(r"\1", s), l), vals) + vals = map(lambda l: map(lambda s: re.sub(r"Failed", r"1", s), l), vals) + vals = map(lambda l: map(lambda s: re.sub(r"Passed", r"0", s), l), vals) with open("out.csv", "w") as f: wr = csv.writer(f) wr.writerow(headers) - wr.writerows([[td.text.encode("utf-8") for td in row.find_all("td")] for row in table.select("tr + tr")]) + wr.writerows(vals) if __name__ == '__main__': main(sys.argv[1]) -- cgit