From ba4875d27a2fc163d06845198b005c26c663ebcd Mon Sep 17 00:00:00 2001 From: Hazel Noack Date: Tue, 10 Jun 2025 16:23:18 +0200 Subject: [PATCH] cleaned up cli --- scribble_to_epub/__main__.py | 14 +++++++++++++- scribble_to_epub/scribblehub.py | 9 ++++----- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/scribble_to_epub/__main__.py b/scribble_to_epub/__main__.py index bcb5ad0..374618a 100644 --- a/scribble_to_epub/__main__.py +++ b/scribble_to_epub/__main__.py @@ -8,17 +8,29 @@ def cli(): description="Scribble_to_epub\n\nThis scrapes books from https://www.scribblehub.com/ and creates EPUB from them.", formatter_class=argparse.RawTextHelpFormatter ) + parser.add_argument( "url", type=str, help="URL of the ScribbleHub story to scrape and convert to EPUB" ) + parser.add_argument( + "--output", + type=str, + default=None, + help="Optional output file name for the EPUB" + ) + parser.add_argument( + "--disable-author-quotes", + action="store_true", + help="Disable author quotes in the EPUB (default: False). I didn't want to implement this because I wanna appreciate the author and what they have to say. Sadly I did not find a way to embed quotes nicely in the epub. So only use it if you have to." + ) args = parser.parse_args() print(f"Running scribble_to_epub for URL: {args.url}") - scribble_book = ScribbleBook(args.url, disable_author_quotes=True) + scribble_book = ScribbleBook(args.url, disable_author_quotes=args.disable_author_quotes, file_name=args.output) scribble_book.load() scribble_book.build() diff --git a/scribble_to_epub/scribblehub.py b/scribble_to_epub/scribblehub.py index 142cb7b..47e9d8d 100644 --- a/scribble_to_epub/scribblehub.py +++ b/scribble_to_epub/scribblehub.py @@ -64,7 +64,7 @@ def get_request(session: requests.Session, url: str, attempt: int = 0) -> reques to_wait = current_delay - elapsed_time if to_wait > 0: - print(f"waiting {to_wait} at attempt {attempt}: {url}") + log.info(f"waiting {to_wait} at attempt {attempt}: {url}") time.sleep(to_wait) last_request = time.time() @@ -304,14 +304,14 @@ class ScribbleBook: def load(self, limit_chapters: Optional[int] = None): self.load_metadata() - print(f"{self.title} by {self.author}:") + print(f"{self.title} by {self.author} with {self.chapter_count} chapters:") self.fetch_chapters(limit=limit_chapters) if limit_chapters is not None: self.chapters = self.chapters[:limit_chapters] - for chapter in self.chapters: - print(f"- {chapter.title}") + for i, chapter in enumerate(self.chapters): + print(f"- {i+1}: {chapter.title}") chapter.load() def load_metadata(self) -> None: @@ -337,7 +337,6 @@ class ScribbleBook: log.warning(f"Metadata URL mismatch!\n\t{self.source_url}\n\t{url}") self.title = soup.find(property="og:title")["content"] - print(f"Book Title: {self.title}") self.cover_url = soup.find(property="og:image")["content"] or "" self.add_asset(self.cover_url)