Skip to content

Commit

Permalink
Bump version: 0.5.0 → 0.5.1
Browse files Browse the repository at this point in the history
Added exception catches for ConnectionError & TimeoutError
  • Loading branch information
arzkar committed Jan 19, 2022
1 parent baedc01 commit 121fa22
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.5.0
current_version = 0.5.1
commit = True
tag = False
parse = ^
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ fichub_cli -l "https://www.fanfiction.net/s/11191235/1/Harry-Potter-and-the-Prin
fichub_cli --get-urls https://archiveofourown.org/users/flamethrower/
```

# Plugins Support
# Plugin Support

Read the [wiki](https://github.com/FicHub/fichub-cli/wiki/Plugins) for more info.

Expand Down
15 changes: 10 additions & 5 deletions fichub_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,11 @@ def default(
return

if log:
debug = True
# debug = True
typer.echo(
Fore.GREEN + f"Creating fichub_cli - {timestamp}.log in the current directory")
Fore.GREEN + "Creating " + Style.RESET_ALL + Fore.YELLOW +
f"fichub_cli - {timestamp}.log" + Style.RESET_ALL +
Fore.GREEN + " in the current directory!" + Style.RESET_ALL)
logger.add(f"fichub_cli - {timestamp}.log")

format_type = get_format_type(format)
Expand All @@ -112,7 +114,7 @@ def default(
fic.get_urls_from_page(get_urls)

if version:
typer.echo("fichub-cli: v0.5.0")
typer.echo("fichub-cli: v0.5.1")

if supported_sites:
typer.echo(Fore.GREEN + """
Expand Down Expand Up @@ -142,8 +144,11 @@ def default(
""")
try:
if fic.exit_status == 1:
typer.echo(Fore.RED + """
Unsupported URLs found! Check err.log in the current directory!""" + Style.RESET_ALL)
typer.echo(
Fore.RED +
"\nDownload failed for one or more URLs! Check " + Style.RESET_ALL +
Fore.YELLOW + "err.log" + Style.RESET_ALL + Fore.RED +
" in the current directory!" + Style.RESET_ALL)
sys.exit(fic.exit_status)
except UnboundLocalError:
sys.exit(0)
64 changes: 44 additions & 20 deletions fichub_cli/utils/fichub.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
from requests.packages.urllib3.util.retry import Retry

import re
import time
from colorama import Fore, Style
from tqdm import tqdm
from loguru import logger

headers = {
'User-Agent': 'fichub_cli/0.5.0',
'User-Agent': 'fichub_cli/0.5.1',
}

retry_strategy = Retry(
Expand Down Expand Up @@ -37,17 +38,27 @@ def get_fic_metadata(self, url: str, format_type: int):
logger.debug(
"--automated flag was passed. Internal Testing mode is on.")

response = self.http.get(
"https://fichub.net/api/v0/epub", params=params,
allow_redirects=True, headers=headers, timeout=(6.1, 300)
)

if self.debug:
logger.debug(f"GET: {response.status_code}: {response.url}")

self.response = response.json()
for _ in range(2):
try:
response = self.http.get(
"https://fichub.net/api/v0/epub", params=params,
allow_redirects=True, headers=headers, timeout=(6.1, 300)
)
if self.debug:
logger.debug(
f"GET: {response.status_code}: {response.url}")
break
except (ConnectionError, TimeoutError, Exception) as e:
if self.debug:
logger.error(str(e))
tqdm.write("\n" + Fore.RED + str(e) + Style.RESET_ALL +
Fore.GREEN + "\nWill retry in 3s!" +
Style.RESET_ALL)
time.sleep(3)

try:
self.response = response.json()

if format_type == 0:
cache_url = self.response['epub_url']
self.cache_hash = (
Expand Down Expand Up @@ -79,28 +90,41 @@ def get_fic_metadata(self, url: str, format_type: int):

# Error: 'epub_url'
# Reason: Unsupported URL
except KeyError:
except (KeyError, UnboundLocalError) as e:
if self.debug:
logger.error(str(e))

self.exit_status = 1
if self.debug:
logger.error(
f"Skipping unsupported URL: {url}")
else:
tqdm.write(
Fore.RED + f"Skipping unsupported URL: {url}" +
Fore.RED + f"\nSkipping unsupported URL: {url}" +
Style.RESET_ALL + Fore.CYAN +
"\nTo see the supported site list, use -s flag")
"\nTo see the supported site list, use " + Fore.YELLOW +
"fichub_cli -ss" + Style.RESET_ALL + Fore.CYAN +
"\nReport the error if the URL is supported!\n")

def get_fic_data(self, download_url: str):

params = {}
if self.automated: # for internal testing
params['automated'] = 'true'

self.response_data = self.http.get(
download_url, allow_redirects=True, headers=headers,
params=params, timeout=(6.1, 300))

if self.debug:
logger.debug(
f"GET: {self.response_data.status_code}: {self.response_data.url}")
for _ in range(2):
try:
self.response_data = self.http.get(
download_url, allow_redirects=True, headers=headers,
params=params, timeout=(6.1, 300))
if self.debug:
logger.debug(
f"GET: {self.response_data.status_code}: {self.response_data.url}")
break
except (ConnectionError, TimeoutError, Exception) as e:
if self.debug:
logger.error(str(e))
tqdm.write("\n" + Fore.RED + str(e) + Style.RESET_ALL +
Fore.GREEN + "\nWill retry in 3s!" +
Style.RESET_ALL)
time.sleep(3)
6 changes: 4 additions & 2 deletions fichub_cli/utils/processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,11 @@ def check_url(url: str, debug: bool = False,
f"Skipping unsupported URL: {url}")
else:
tqdm.write(
Fore.RED + f"Skipping unsupported URL: {url}" +
Fore.RED + f"\nSkipping unsupported URL: {url}" +
Style.RESET_ALL + Fore.CYAN +
"\nTo see the supported site list, use -s flag")
"\nTo see the supported site list, use " + Fore.YELLOW +
"fichub_cli -ss" + Style.RESET_ALL + Fore.CYAN +
"\nReport the error if the URL is supported!\n")

return False, exit_status

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
description="A CLI for the fichub.net API",
long_description=long_description,
long_description_content_type="text/markdown",
version='0.5.0',
version='0.5.1',
license='MIT',
url="https://github.com/FicHub/fichub-cli",
packages=find_packages(include=['fichub_cli', 'fichub_cli.*']),
Expand Down
2 changes: 1 addition & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ def test_cli_version():

assert not result.exception
assert result.exit_code == 0
assert result.output.strip() == 'fichub-cli: v0.5.0'
assert result.output.strip() == 'fichub-cli: v0.5.1'

0 comments on commit 121fa22

Please sign in to comment.