Skip to content

Commit 50c9903

Browse files
committed
Added debug, output directory and version info options to the CLI
- src/fichub_cli.py: Added debug, output directory and version info options - src/util.py: Added logging for debug mode - setup.py: Added long_description & classifiers - Added README.md, MANIFEST.in, setup.cfg, pyproject.toml
1 parent 4237265 commit 50c9903

10 files changed

+116
-24
lines changed

LICENSE LICENSE.txt

File renamed without changes.

MANIFEST.in

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
include pyproject.toml
2+
include *.md
3+
include LICENSE.txt
4+
include setup.py
5+
global-exclude *.pyc
6+
recursive-include src *.py

README.md

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<h1 align="center">fichub-cli</h1>
2+
3+
A CLI for the fichub.net API<br>
4+
5+
# Installation
6+
7+
## Pip method
8+
9+
Install the package using pip
10+
11+
```
12+
pip install -U fichub_cli
13+
```
14+
15+
## Executable method
16+
17+
Download the executables from [Releases](https://github.com/FicHub/fichub-cli/releases) and run them.
18+
19+
### Linux
20+
21+
```
22+
\.fichub_cli --help
23+
```
24+
25+
# Usage
26+
27+
```
28+
> fichub_cli --help
29+
Usage: fichub_cli [OPTIONS]
30+
31+
Options:
32+
-i, --infile TEXT Give a filename to read URLs from
33+
-o, --out_dir TEXT Output directory for files
34+
-f, --format TEXT Download Format: epub(default), mobi, pdf or html
35+
-l, --list_url TEXT Enter a list of urls to download separated by comma
36+
enclosed in quotes
37+
38+
-u, --url TEXT The url of the fanfiction
39+
-d, --debug Debug mode
40+
-v, --version Display version & quit.
41+
--help Show this message and exit.
42+
```

pyproject.toml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[build-system]
2+
# These are the assumed default build requirements from pip:
3+
# https://pip.pypa.io/en/stable/reference/pip/#pep-517-and-518-support
4+
requires = ["setuptools>=52.0.0", "wheel"]
5+
build-backend = "setuptools.build_meta"

requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ chardet==4.0.0
44
click==7.1.2
55
flake8==3.9.1
66
idna==2.10
7+
loguru==0.5.3
78
mccabe==0.6.1
89
pip==21.0.1
910
pycodestyle==2.7.0

setup.cfg

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[metadata]
2+
license-file = LICENSE.txt
3+
description-file = README.md

setup.py

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
from setuptools import setup, find_packages
22

3+
with open("README.md", "r") as f:
4+
long_description = f.read()
5+
36
setup(
47
name='fichub-cli',
58
author='arzkar',
69
author_email="[email protected]",
7-
description="A CLI for the fichub.net API",
10+
description="A CLI tool for the fichub.net API",
11+
long_description=long_description,
12+
long_description_content_type="text/markdown",
813
version='0.1',
14+
license='MIT',
15+
url="https://github.com/FicHub/fichub_cli",
916
package_dir={"": "src"},
1017
packages=find_packages(where="src"),
1118
include_package_data=True,
@@ -17,4 +24,12 @@
1724
[console_scripts]
1825
fichub_cli=fichub_cli:cli
1926
''',
27+
classifiers=[
28+
'Development Status :: 5 - Stable',
29+
'Intended Audience :: Developers',
30+
'Topic :: Software Development :: CLI Tool',
31+
"Programming Language :: Python :: 3",
32+
"License :: OSI Approved :: MIT License",
33+
"Operating System :: OS Independent",
34+
],
2035
)

src/fichub.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ def get_fic_data(url, format_type):
2626
download_url = "https://fichub.net"+cache_url
2727
data = requests.get(download_url, allow_redirects=True).content
2828

29-
return fic_name + file_format, data
29+
return fic_name, file_format, data

src/fichub_cli.py

+18-12
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,24 @@
44

55

66
@click.command()
7-
@click.option('-i', '--INFILE', default=None, help='Give a filename to read URLs from')
8-
@click.option('-f', '--FORMAT', default="epub", help='Download Format: epub(default), mobi, pdf or html')
9-
@click.option('-l', '--list_URL', default=None, help='Enter a list of urls to download separated by comma enclosed in quotes')
10-
@click.option('-u', '--URL', default=None, help='The url of the fanfiction')
11-
def cli(INFILE, URL, list_URL, FORMAT):
7+
@click.option('-i', '--infile', default=None, help='Give a filename to read URLs from')
8+
@click.option('-o', '--out_dir', default="", help='Output directory for files')
9+
@click.option('-f', '--format', default="epub", help='Download Format: epub(default), mobi, pdf or html')
10+
@click.option('-l', '--list_url', default=None, help='Enter a list of urls to download separated by comma enclosed in quotes')
11+
@click.option('-u', '--url', default=None, help='The url of the fanfiction')
12+
@click.option('-d', '--debug', default=False, help='Debug mode', is_flag=True)
13+
@click.option('-v', '--version', default=False, help='Display version & quit.', is_flag=True)
14+
def cli(infile, url, list_url, format, out_dir, debug, version):
1215

13-
format_type = get_format_type(FORMAT)
14-
if INFILE:
15-
get_fic_with_infile(INFILE, format_type)
16+
format_type = get_format_type(format)
17+
if infile:
18+
get_fic_with_infile(infile, format_type, out_dir, debug)
1619

17-
elif list_URL:
18-
get_fic_with_list(list_URL, format_type)
20+
elif list_url:
21+
get_fic_with_list(list_url, format_type, out_dir, debug)
1922

20-
elif URL:
21-
get_fic_with_url(URL, format_type)
23+
elif url:
24+
get_fic_with_url(url, format_type, out_dir, debug)
25+
26+
if version:
27+
click.echo("Version: 0.1")

src/util.py

+24-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import click
2+
from loguru import logger
3+
24
from fichub import get_fic_data
35

46

@@ -21,7 +23,7 @@ def get_format_type(format):
2123
return format_type
2224

2325

24-
def get_fic_with_infile(infile=None, format_type=0):
26+
def get_fic_with_infile(infile=None, format_type=0, out_dir="", debug=False):
2527

2628
with open(infile, "r") as f:
2729
urls = f.read().splitlines()
@@ -30,28 +32,40 @@ def get_fic_with_infile(infile=None, format_type=0):
3032
with click.progressbar(urls, label=f"Downloading {len(urls)} files", length=len(urls)) as bar:
3133
for url in bar:
3234
count += 1
33-
file_name, data = get_fic_data(url, format_type)
34-
with open(file_name, "wb") as f:
35+
fic_name, file_format, data = get_fic_data(url, format_type)
36+
37+
if debug:
38+
logger.debug(f"Downloading {count}/{len(urls)}: {fic_name}")
39+
40+
with open(out_dir+fic_name+file_format, "wb") as f:
3541
f.write(data)
3642

3743

38-
def get_fic_with_list(list_url=None, format_type=0):
44+
def get_fic_with_list(list_url=None, format_type=0, out_dir="", debug=False):
3945

4046
urls = list_url.split(",")
4147

4248
count = 1
4349
with click.progressbar(urls, label=f"Downloading {len(urls)} files", length=len(urls)) as bar:
4450
for url in bar:
4551
count += 1
46-
file_name, data = get_fic_data(url, format_type)
47-
with open(file_name, "wb") as f:
52+
fic_name, file_format, data = get_fic_data(url, format_type)
53+
54+
if debug:
55+
logger.debug(f"Downloading {count}/{len(urls)}: {fic_name}")
56+
57+
with open(out_dir+fic_name+file_format, "wb") as f:
4858
f.write(data)
4959

5060

51-
def get_fic_with_url(url=None, format_type=0):
61+
def get_fic_with_url(url=None, format_type=0, out_dir="", debug=False):
62+
63+
with click.progressbar(label="Downloaded 1 file", length=1) as bar:
64+
fic_name, file_format, data = get_fic_data(url, format_type)
65+
66+
if debug:
67+
logger.debug(f"Downloading 1/1: {fic_name}")
5268

53-
with click.progressbar(label="Downloading 1 file", length=1) as bar:
54-
file_name, data = get_fic_data(url, format_type)
55-
with open(file_name, "wb") as f:
69+
with open(out_dir+fic_name+file_format, "wb") as f:
5670
f.write(data)
5771
bar.update(2)

0 commit comments

Comments
 (0)