From 9c200a12466df611ea2fae9768c0db5001aa5e17 Mon Sep 17 00:00:00 2001 From: Felix Martin Date: Mon, 24 Oct 2022 20:36:31 -0400 Subject: [PATCH] Exit with warning if epub is annotated (resolves #4) --- src/epub.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/epub.py b/src/epub.py index 82c0631..a02f986 100644 --- a/src/epub.py +++ b/src/epub.py @@ -11,12 +11,12 @@ from rich.progress import track from rich.console import Console POKEMON_ID_PREFIX = "pokemon-id-" +POKEDEX_UID = "np_pokedex" def create_pokedex_chapter(pokemon: List[Pokemon]) -> epub.EpubHtml: POKEDEX_TITLE = "Pokedex" POKEDEX_FILE = "content/np_pokedex.xhtml" - POKEDEX_UID = "np_pokedex" chapter = epub.EpubHtml( title=POKEDEX_TITLE, file_name=POKEDEX_FILE, uid=POKEDEX_UID ) @@ -95,6 +95,11 @@ def patch(epub_filename: str, pokemon: List[Pokemon]): if isinstance(b, epub.EpubHtml) if b.id.startswith("np_") ] + + if [c for c in chapters if c.id == POKEDEX_UID]: + logging.warning(f"It looks like '{epub_filename}' already has a Pokedex.") + sys.exit(1) + for c in track(chapters, description="Add Pokemon links to chapters"): patch_chapter(c, pokemon_lookup)