generated from Hazel/python-project
cleaned up cli
This commit is contained in:
parent
62a6bc387f
commit
ba4875d27a
@ -8,17 +8,29 @@ def cli():
|
|||||||
description="Scribble_to_epub\n\nThis scrapes books from https://www.scribblehub.com/ and creates EPUB from them.",
|
description="Scribble_to_epub\n\nThis scrapes books from https://www.scribblehub.com/ and creates EPUB from them.",
|
||||||
formatter_class=argparse.RawTextHelpFormatter
|
formatter_class=argparse.RawTextHelpFormatter
|
||||||
)
|
)
|
||||||
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"url",
|
"url",
|
||||||
type=str,
|
type=str,
|
||||||
help="URL of the ScribbleHub story to scrape and convert to EPUB"
|
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()
|
args = parser.parse_args()
|
||||||
|
|
||||||
print(f"Running scribble_to_epub for URL: {args.url}")
|
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.load()
|
||||||
scribble_book.build()
|
scribble_book.build()
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ def get_request(session: requests.Session, url: str, attempt: int = 0) -> reques
|
|||||||
to_wait = current_delay - elapsed_time
|
to_wait = current_delay - elapsed_time
|
||||||
|
|
||||||
if to_wait > 0:
|
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)
|
time.sleep(to_wait)
|
||||||
|
|
||||||
last_request = time.time()
|
last_request = time.time()
|
||||||
@ -304,14 +304,14 @@ class ScribbleBook:
|
|||||||
|
|
||||||
def load(self, limit_chapters: Optional[int] = None):
|
def load(self, limit_chapters: Optional[int] = None):
|
||||||
self.load_metadata()
|
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)
|
self.fetch_chapters(limit=limit_chapters)
|
||||||
if limit_chapters is not None:
|
if limit_chapters is not None:
|
||||||
self.chapters = self.chapters[:limit_chapters]
|
self.chapters = self.chapters[:limit_chapters]
|
||||||
|
|
||||||
for chapter in self.chapters:
|
for i, chapter in enumerate(self.chapters):
|
||||||
print(f"- {chapter.title}")
|
print(f"- {i+1}: {chapter.title}")
|
||||||
chapter.load()
|
chapter.load()
|
||||||
|
|
||||||
def load_metadata(self) -> None:
|
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}")
|
log.warning(f"Metadata URL mismatch!\n\t{self.source_url}\n\t{url}")
|
||||||
|
|
||||||
self.title = soup.find(property="og:title")["content"]
|
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.cover_url = soup.find(property="og:image")["content"] or ""
|
||||||
self.add_asset(self.cover_url)
|
self.add_asset(self.cover_url)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user