diff options
-rwxr-xr-x[-rw-r--r--] | scripts/convert.py | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/scripts/convert.py b/scripts/convert.py index e179774..a1e68ca 100644..100755 --- 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]) |