diff options
Diffstat (limited to 'scripts/convert.py')
-rwxr-xr-x | scripts/convert.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/scripts/convert.py b/scripts/convert.py new file mode 100755 index 0000000..d592fd6 --- /dev/null +++ b/scripts/convert.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python3 + +import sys +from bs4 import BeautifulSoup +import csv +import re + +def main(file_, output): + with open(file_, "r") as f: + file_contents = f.read() + + sec = re.compile(r"([0-9.]+)s") + + soup = BeautifulSoup(file_contents, "html.parser") + table = soup.select_one("table.table") + 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(output, "w") as f: + wr = csv.writer(f) + wr.writerow(headers) + wr.writerows(vals) + +if __name__ == '__main__': + main(sys.argv[1], sys.argv[2]) |