cleaned up cli

This commit is contained in:
Hazel Noack 2025-06-10 16:23:18 +02:00
parent 62a6bc387f
commit ba4875d27a
2 changed files with 17 additions and 6 deletions

View File

@ -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()

View File

@ -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)