From: Armaan Bhojwani Date: Tue, 9 Feb 2021 04:30:54 +0000 (-0500) Subject: Move from script to using entry point in setup.py X-Git-Tag: v0.6.0~37 X-Git-Url: https://git.armaanb.net/?p=lightcards.git;a=commitdiff_plain;h=f5f8332aa1136c3fc878f410e56cddbcc7f143fb Move from script to using entry point in setup.py --- diff --git a/bin/kvtml2html.py b/bin/kvtml2html.py deleted file mode 100755 index 9a28303..0000000 --- a/bin/kvtml2html.py +++ /dev/null @@ -1,42 +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"" - for i in range(len(col1)): - try: - html += f"
{headers[0]}{headers[1]}
" - html += f"" - except: - pass - - with open(args.outp[0], "w", encoding="utf-8") as output_file: - output_file.write(html) - - -if __name__ == "__main__": - main() diff --git a/bin/lightcards b/bin/lightcards deleted file mode 100755 index fec8f88..0000000 --- a/bin/lightcards +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env python - -import lightcards - -lightcards.lightcards.main() diff --git a/contrib/kvtml2html.py b/contrib/kvtml2html.py new file mode 100755 index 0000000..9a28303 --- /dev/null +++ b/contrib/kvtml2html.py @@ -0,0 +1,42 @@ +#!/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"
{col1[i].get_text().rstrip()}{col2[i].get_text().rstrip()}
" + for i in range(len(col1)): + try: + html += f"
{headers[0]}{headers[1]}
" + html += f"" + except: + pass + + with open(args.outp[0], "w", encoding="utf-8") as output_file: + output_file.write(html) + + +if __name__ == "__main__": + main() diff --git a/setup.py b/setup.py index 93ca495..0f60632 100644 --- a/setup.py +++ b/setup.py @@ -18,7 +18,9 @@ setup( packages=["lightcards"], install_requires=["beautifulsoup4", "markdown"], data_files=[("man/man1", ["man/lightcards.1"])], - scripts=["bin/lightcards"], + entry_points={ + "console_scripts": ["lightcards=lightcards:main"], + }, classifiers=[ "Intended Audience :: Education", "Environment :: Console :: Curses",
{col1[i].get_text().rstrip()}{col2[i].get_text().rstrip()}