From ce5f113be919cc776ed77151eca87d469573eab6 Mon Sep 17 00:00:00 2001 From: Luke Tao Date: Fri, 29 Sep 2023 20:29:07 -0400 Subject: [PATCH] Fix bug where install didn't have template files --- README.md | 1 + setup.cfg | 4 ++++ .../AnkiChinese/card_template}/_CNstrokeorder.ttf | Bin src/AnkiChinese/card_template/__init__.py | 0 .../AnkiChinese/card_template}/back.html | 0 .../AnkiChinese/card_template}/front.html | 0 .../AnkiChinese/card_template}/styles.css | 0 src/AnkiChinese/export.py | 14 +++++++++----- src/AnkiChinese/main.py | 4 ++++ 9 files changed, 18 insertions(+), 5 deletions(-) rename {card_template => src/AnkiChinese/card_template}/_CNstrokeorder.ttf (100%) create mode 100644 src/AnkiChinese/card_template/__init__.py rename {card_template => src/AnkiChinese/card_template}/back.html (100%) rename {card_template => src/AnkiChinese/card_template}/front.html (100%) rename {card_template => src/AnkiChinese/card_template}/styles.css (100%) diff --git a/README.md b/README.md index 4757dc7..673a2c9 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,7 @@ Asynchronously scrape the ArchChinese dictionary to generate [Anki](https://apps # Installation pip install ankichinese + playwright install # Usage diff --git a/setup.cfg b/setup.cfg index 5761780..01857f7 100644 --- a/setup.cfg +++ b/setup.cfg @@ -29,6 +29,10 @@ install_requires = genanki tqdm requests + ankipandas + +[options.package_data] +* = *.html, *.css, *.ttf [options.packages.find] where = src diff --git a/card_template/_CNstrokeorder.ttf b/src/AnkiChinese/card_template/_CNstrokeorder.ttf similarity index 100% rename from card_template/_CNstrokeorder.ttf rename to src/AnkiChinese/card_template/_CNstrokeorder.ttf diff --git a/src/AnkiChinese/card_template/__init__.py b/src/AnkiChinese/card_template/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/card_template/back.html b/src/AnkiChinese/card_template/back.html similarity index 100% rename from card_template/back.html rename to src/AnkiChinese/card_template/back.html diff --git a/card_template/front.html b/src/AnkiChinese/card_template/front.html similarity index 100% rename from card_template/front.html rename to src/AnkiChinese/card_template/front.html diff --git a/card_template/styles.css b/src/AnkiChinese/card_template/styles.css similarity index 100% rename from card_template/styles.css rename to src/AnkiChinese/card_template/styles.css diff --git a/src/AnkiChinese/export.py b/src/AnkiChinese/export.py index d990a85..707997f 100644 --- a/src/AnkiChinese/export.py +++ b/src/AnkiChinese/export.py @@ -10,14 +10,18 @@ def gen_csv(results, output_name): df.to_csv(output_name + ".csv", index=False, sep="\t") +def get_full_path(relative_path): + return os.path.join(os.path.dirname(__file__), relative_path) + + def gen_model(): - front_html = open("card_template/front.html", "r") + front_html = open(get_full_path("card_template/front.html"), "r") front = front_html.read() front_html.close() - back_html = open("card_template/back.html", "r") + back_html = open(get_full_path("card_template/back.html"), "r") back = back_html.read() back_html.close() - styles_css = open("card_template/styles.css", "r") + styles_css = open(get_full_path("card_template/styles.css"), "r") styles = styles_css.read() styles_css.close() @@ -30,7 +34,7 @@ def gen_model(): {"name": "Definition"}, {"name": "Pinyin"}, {"name": "Pinyin 2"}, - {"name": "Words"}, + {"name": "Examples"}, {"name": "Formation"}, {"name": "HSK"}, {"name": "Audio"}, @@ -79,7 +83,7 @@ def gen_anki(results, output_name): package = genanki.Package(deck) add_audio(package, "ankichinese_audio") - package.media_files.append("card_template/_CNstrokeorder.ttf") + package.media_files.append(get_full_path("card_template/_CNstrokeorder.ttf")) package.write_to_file(output_name + ".apkg") diff --git a/src/AnkiChinese/main.py b/src/AnkiChinese/main.py index ced1c87..9bda2e1 100644 --- a/src/AnkiChinese/main.py +++ b/src/AnkiChinese/main.py @@ -1,3 +1,7 @@ +import sys +import os.path + +sys.path.insert(1, os.path.dirname(__file__)) import scraper import export