diff --git a/crowd_anki/export/anki_exporter.py b/crowd_anki/export/anki_exporter.py index 25c2603..06812f9 100644 --- a/crowd_anki/export/anki_exporter.py +++ b/crowd_anki/export/anki_exporter.py @@ -9,7 +9,7 @@ from ..anki.adapters.anki_deck import AnkiDeck from ..representation import deck_initializer from ..representation.deck import Deck -from ..utils.constants import DECK_FILE_EXTENSION, MEDIA_SUBDIRECTORY_NAME +from ..utils.constants import DECK_FILE_NAME, DECK_FILE_EXTENSION, MEDIA_SUBDIRECTORY_NAME from ..utils.filesystem.name_sanitizer import sanitize_anki_deck_name @@ -28,7 +28,7 @@ def export_to_directory(self, deck: AnkiDeck, output_dir=Path("."), copy_media=T deck = deck_initializer.from_collection(self.collection, deck.name) self.last_exported_count = deck.get_note_count() - deck_filename = deck_directory.joinpath('deck').with_suffix(DECK_FILE_EXTENSION) + deck_filename = deck_directory.joinpath(DECK_FILE_NAME).with_suffix(DECK_FILE_EXTENSION) with deck_filename.open(mode='w', encoding="utf8") as deck_file: deck_file.write(json.dumps(deck, default=Deck.default_json, diff --git a/crowd_anki/importer/anki_importer.py b/crowd_anki/importer/anki_importer.py index 9325a75..0341449 100644 --- a/crowd_anki/importer/anki_importer.py +++ b/crowd_anki/importer/anki_importer.py @@ -8,7 +8,7 @@ import aqt import aqt.utils from ..representation import deck_initializer -from ..utils.constants import DECK_FILE_EXTENSION, MEDIA_SUBDIRECTORY_NAME +from ..utils.constants import DECK_FILE_NAME, DECK_FILE_EXTENSION, MEDIA_SUBDIRECTORY_NAME class AnkiJsonImporter(object): @@ -32,8 +32,8 @@ def load_from_file(self, file_path): def load_from_directory(self, directory_path, import_media=True): """ Load deck serialized to directory - Assumes that deck json file is located in the directory and named - same way as a directory but with json file extension. + Assumes that deck json file is located in the directory + and named 'deck.json' :param import_media: Should we copy media? :type directory_path: Path """ @@ -42,7 +42,10 @@ def load_from_directory(self, directory_path, import_media=True): aqt.mw.progress.start(immediate=True) try: - self.load_from_file(directory_path.joinpath('deck').with_suffix(DECK_FILE_EXTENSION)) + try: + self.load_from_file(directory_path.joinpath(DECK_FILE_NAME).with_suffix(DECK_FILE_EXTENSION)) + except ValueError: + self.load_from_file(directory_path.joinpath(directory_path.name).with_suffix(DECK_FILE_EXTENSION)) if import_media: media_directory = directory_path.joinpath(MEDIA_SUBDIRECTORY_NAME) diff --git a/crowd_anki/utils/constants.py b/crowd_anki/utils/constants.py index b968f0f..c04fc9e 100644 --- a/crowd_anki/utils/constants.py +++ b/crowd_anki/utils/constants.py @@ -1,7 +1,7 @@ from pathlib import Path UUID_FIELD_NAME = 'crowdanki_uuid' - +DECK_FILE_NAME = "deck" DECK_FILE_EXTENSION = ".json" MEDIA_SUBDIRECTORY_NAME = "media"