feat: cli using click
This commit is contained in:
@@ -1,11 +1,12 @@
|
|||||||
[project]
|
[project]
|
||||||
name = "epub2go"
|
name = "epub2go"
|
||||||
version = "1.2"
|
version = "1.3"
|
||||||
description = "EPUB converter using wget, pandoc and python glue"
|
description = "EPUB converter using wget, pandoc and python glue"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
requires-python = ">=3.12"
|
requires-python = ">=3.12"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"beautifulsoup4==4.12.3",
|
"beautifulsoup4==4.12.3",
|
||||||
|
"click>=8.1.8",
|
||||||
"pyfzf>=0.3.1", # hasnt been updated for some time
|
"pyfzf>=0.3.1", # hasnt been updated for some time
|
||||||
"requests==2.32.3",
|
"requests==2.32.3",
|
||||||
"tqdm>=4.67.1",
|
"tqdm>=4.67.1",
|
||||||
|
|||||||
@@ -5,8 +5,9 @@ from urllib.parse import urljoin
|
|||||||
from urllib.request import urlparse
|
from urllib.request import urlparse
|
||||||
from tqdm import tqdm
|
from tqdm import tqdm
|
||||||
from pyfzf.pyfzf import FzfPrompt
|
from pyfzf.pyfzf import FzfPrompt
|
||||||
|
import click
|
||||||
|
|
||||||
import os, sys, subprocess, shlex, logging
|
import os, subprocess, shlex, logging
|
||||||
import importlib.resources as pkg_resources
|
import importlib.resources as pkg_resources
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import List
|
from typing import List
|
||||||
@@ -147,12 +148,20 @@ def get_all_books() -> List[Book]:
|
|||||||
return books
|
return books
|
||||||
|
|
||||||
# run main cli
|
# run main cli
|
||||||
def main():
|
@click.command()
|
||||||
logging.basicConfig(level=logging.NOTSET,format='%(asctime)s - %(levelname)s - %(message)s')
|
@click.option('--debug', '-d', is_flag=True, help='Set the log level to DEBUG')
|
||||||
sys.argv.pop(0)
|
@click.option('--silent', '-s', is_flag=True, help='Disable the progress bar')
|
||||||
|
@click.argument('args', nargs=-1)
|
||||||
|
def main(args, debug, silent):
|
||||||
|
'''
|
||||||
|
Download ePUBs from https://www.projekt-gutenberg.org/
|
||||||
|
Provide either 0 arguments to enter interactive mode or an arbitrary number of URLs to download from
|
||||||
|
'''
|
||||||
|
logging.basicConfig(level=logging.ERROR,format='%(asctime)s - %(levelname)s - %(message)s')
|
||||||
|
if(debug): logger.setLevel(logging.DEBUG)
|
||||||
# non-interactive mode
|
# non-interactive mode
|
||||||
if len(sys.argv) > 0 :
|
if len(args) > 0 :
|
||||||
books = sys.argv
|
books = args
|
||||||
# interactive mode using fzf
|
# interactive mode using fzf
|
||||||
else:
|
else:
|
||||||
logger.debug('Received no CLI arguments, starting interactive mode')
|
logger.debug('Received no CLI arguments, starting interactive mode')
|
||||||
@@ -163,11 +172,11 @@ def main():
|
|||||||
selection = fzf.prompt(choices=books, fzf_options=r'--exact --with-nth 1 -m -d\;')
|
selection = fzf.prompt(choices=books, fzf_options=r'--exact --with-nth 1 -m -d\;')
|
||||||
books = [item.split(';')[1].strip() for item in selection]
|
books = [item.split(';')[1].strip() for item in selection]
|
||||||
|
|
||||||
logger.debug('Attempting to download from %d URLs', len(books))
|
logger.debug('Attempting to download from %d URL(s)', len(books))
|
||||||
if len(books)==1:
|
if len(books)==1:
|
||||||
GBConvert(books[0], showprogress=True).run()
|
GBConvert(books[0], showprogress=not silent).run()
|
||||||
else:
|
else:
|
||||||
for book in tqdm(books):
|
for book in (tqdm(books) if not silent else books):
|
||||||
GBConvert(book).run()
|
GBConvert(book).run()
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|||||||
15
uv.lock
generated
15
uv.lock
generated
@@ -1,4 +1,5 @@
|
|||||||
version = 1
|
version = 1
|
||||||
|
revision = 1
|
||||||
requires-python = ">=3.12"
|
requires-python = ">=3.12"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -57,6 +58,18 @@ wheels = [
|
|||||||
{ url = "https://files.pythonhosted.org/packages/0e/f6/65ecc6878a89bb1c23a086ea335ad4bf21a588990c3f535a227b9eea9108/charset_normalizer-3.4.1-py3-none-any.whl", hash = "sha256:d98b1668f06378c6dbefec3b92299716b931cd4e6061f3c875a71ced1780ab85", size = 49767 },
|
{ url = "https://files.pythonhosted.org/packages/0e/f6/65ecc6878a89bb1c23a086ea335ad4bf21a588990c3f535a227b9eea9108/charset_normalizer-3.4.1-py3-none-any.whl", hash = "sha256:d98b1668f06378c6dbefec3b92299716b931cd4e6061f3c875a71ced1780ab85", size = 49767 },
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "click"
|
||||||
|
version = "8.1.8"
|
||||||
|
source = { registry = "https://pypi.org/simple" }
|
||||||
|
dependencies = [
|
||||||
|
{ name = "colorama", marker = "sys_platform == 'win32'" },
|
||||||
|
]
|
||||||
|
sdist = { url = "https://files.pythonhosted.org/packages/b9/2e/0090cbf739cee7d23781ad4b89a9894a41538e4fcf4c31dcdd705b78eb8b/click-8.1.8.tar.gz", hash = "sha256:ed53c9d8990d83c2a27deae68e4ee337473f6330c040a31d4225c9574d16096a", size = 226593 }
|
||||||
|
wheels = [
|
||||||
|
{ url = "https://files.pythonhosted.org/packages/7e/d4/7ebdbd03970677812aac39c869717059dbb71a4cfc033ca6e5221787892c/click-8.1.8-py3-none-any.whl", hash = "sha256:63c132bbbed01578a06712a2d1f497bb62d9c1c0d329b7903a866228027263b2", size = 98188 },
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "colorama"
|
name = "colorama"
|
||||||
version = "0.4.6"
|
version = "0.4.6"
|
||||||
@@ -72,6 +85,7 @@ version = "1.2"
|
|||||||
source = { editable = "." }
|
source = { editable = "." }
|
||||||
dependencies = [
|
dependencies = [
|
||||||
{ name = "beautifulsoup4" },
|
{ name = "beautifulsoup4" },
|
||||||
|
{ name = "click" },
|
||||||
{ name = "pyfzf" },
|
{ name = "pyfzf" },
|
||||||
{ name = "requests" },
|
{ name = "requests" },
|
||||||
{ name = "tqdm" },
|
{ name = "tqdm" },
|
||||||
@@ -81,6 +95,7 @@ dependencies = [
|
|||||||
[package.metadata]
|
[package.metadata]
|
||||||
requires-dist = [
|
requires-dist = [
|
||||||
{ name = "beautifulsoup4", specifier = "==4.12.3" },
|
{ name = "beautifulsoup4", specifier = "==4.12.3" },
|
||||||
|
{ name = "click", specifier = ">=8.1.8" },
|
||||||
{ name = "pyfzf", specifier = ">=0.3.1" },
|
{ name = "pyfzf", specifier = ">=0.3.1" },
|
||||||
{ name = "requests", specifier = "==2.32.3" },
|
{ name = "requests", specifier = "==2.32.3" },
|
||||||
{ name = "tqdm", specifier = ">=4.67.1" },
|
{ name = "tqdm", specifier = ">=4.67.1" },
|
||||||
|
|||||||
Reference in New Issue
Block a user