X-Git-Url: https://git.armaanb.net/?p=lightcards.git;a=blobdiff_plain;f=contrib%2Fkvtml2html.py;fp=contrib%2Fkvtml2html.py;h=0000000000000000000000000000000000000000;hp=313a44b04010183e739b464d68172a8a2ab985b2;hb=ae89ff9e73baee789bcfa1c914da8e29feb2dc04;hpb=b1a79e70ed02ceeac0f2343067e0f58deff3b37e
diff --git a/contrib/kvtml2html.py b/contrib/kvtml2html.py
deleted file mode 100755
index 313a44b..0000000
--- a/contrib/kvtml2html.py
+++ /dev/null
@@ -1,38 +0,0 @@
-#!/usr/bin/env python
-# Converts .kvtml KWordQuiz files to HTML
-
-import argparse
-from bs4 import BeautifulSoup
-
-
-def parse_args():
- parser = argparse.ArgumentParser(
- description="Convert KWordQuiz file into Markdown for Lightcards")
- parser.add_argument("inp", metavar="input file", type=str, nargs=1)
- parser.add_argument("outp", metavar="output file", type=str, nargs=1)
- return parser.parse_args()
-
-
-def main():
- args = parse_args()
- with open(args.inp[0], "r", encoding="utf-8") as input_file:
- soup = BeautifulSoup(input_file, "lxml")
-
- headers = [x.get_text().split("\n")[1] for x in soup.find_all("identifier")]
- body = soup.find_all("entry")
- col1 = [x.find("translation", {"id": "0"}) for x in body]
- col2 = [x.find("translation", {"id": "1"}) for x in body]
-
- html = f"
{headers[0]} | {headers[1]} |
"
- for i in range(len(col1)):
- try:
- html += f"{col1[i].get_text().rstrip()} | "
- html += f"{col2[i].get_text().rstrip()} |
"
- except:
- pass
-
- with open(args.outp[0], "w", encoding="utf-8") as output_file:
- output_file.write(html)
-
-if __name__ == "__main__":
- main()