2 # Converts .kvtml KWordQuiz files to HTML
5 from bs4 import BeautifulSoup
9 parser = argparse.ArgumentParser(
10 description="Convert KWordQuiz file into Markdown for Lightcards"
12 parser.add_argument("inp", metavar="input file", type=str, nargs=1)
13 parser.add_argument("outp", metavar="output file", type=str, nargs=1)
14 return parser.parse_args()
19 with open(args.inp[0], "r", encoding="utf-8") as input_file:
20 soup = BeautifulSoup(input_file, "lxml")
23 x.get_text().split("\n")[1] for x in soup.find_all("identifier")
25 body = soup.find_all("entry")
26 col1 = [x.find("translation", {"id": "0"}) for x in body]
27 col2 = [x.find("translation", {"id": "1"}) for x in body]
29 html = f"<html><table><tr><th>{headers[0]}</th><th>{headers[1]}</th></tr>"
30 for i in range(len(col1)):
32 html += f"<html><table><tr><td>{col1[i].get_text().rstrip()}</td>"
33 html += f"<td>{col2[i].get_text().rstrip()}</td></tr>"
37 with open(args.outp[0], "w", encoding="utf-8") as output_file:
38 output_file.write(html)
41 if __name__ == "__main__":