This repository has been archived by the owner on Jan 3, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
695e704
commit f4ce202
Showing
6 changed files
with
113 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
"""Merge all downloaded images into a single PDF file""" | ||
|
||
from PIL import Image | ||
|
||
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
"""Download all images of the book from a given URL of one page""" | ||
|
||
from requests import get | ||
|
||
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,56 @@ | ||
from os import get_terminal_size | ||
from os import get_terminal_size, getenv | ||
from typing import Literal | ||
from logging import basicConfig | ||
from datetime import datetime | ||
from dotenv import load_dotenv | ||
from utils import createDirectory | ||
from utils.printColor import printWarning, printInfo | ||
|
||
|
||
LOGGER_MODE = Literal['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'] | ||
DOTENV_TRUE_VALUES: list[str] = ['True', 'true', '1'] | ||
DOTENV_FALSE_VALUES: list[str] = ['False', 'false', '0', '', ' '] | ||
TERMINAL_SIZE_COLUMNS: int = get_terminal_size().columns | ||
|
||
|
||
def pause() -> None: | ||
"""Pause the system | ||
"""Pause the terminal until user hits Enter | ||
Params: | ||
- None | ||
Returns: | ||
- None | ||
""" | ||
_: str = input("Press Enter to continue . . .") | ||
_: str = input('Press Enter to continue . . .') | ||
|
||
|
||
TERMINAL_SIZE_COLUMNS: int = get_terminal_size().columns | ||
def setupLogger(level: str | None = 'INFO') -> None: | ||
"""Setup the logger | ||
Params: | ||
- level (str | None): The level to log at. Only accept DEBUG, INFO, WARNING, ERROR, CRITICAL | ||
Returns: | ||
- None | ||
""" | ||
createDirectory('logs') | ||
file_name: str = datetime.now().strftime(format='%Y-%m-%d-%H-%M-%S') + '.log' | ||
basicConfig( | ||
filename=f'log/{file_name}', | ||
format="%(asctime)s - %(levelname)s - %(message)s - %(filename)s:%(lineno)d", | ||
level=level | ||
) | ||
|
||
|
||
# SETUP LOGGER | ||
load_dotenv(dotenv_path='config.env') | ||
if getenv(key='LOG') in DOTENV_TRUE_VALUES: | ||
LOG_LEVEL: str | None = getenv(key='LOG_LEVEL') | ||
if LOG_LEVEL is None: | ||
printWarning( | ||
message='LOG_LEVEL is not set in config.env. Defaulting to INFO') | ||
setupLogger() | ||
else: | ||
printInfo(message=f'LOG_LEVEL is set to {LOG_LEVEL}') | ||
setupLogger(level=LOG_LEVEL) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
"""Contains utility functions for the project""" | ||
|
||
|
||
from os import makedirs, path, removedirs | ||
|
||
|
||
def createDirectory(*directories: str) -> None: | ||
"""Create directories if they do not exist | ||
Params: | ||
- *directories (str): The directories to create | ||
Returns: | ||
- None | ||
""" | ||
for directory in directories: | ||
if not path.exists(path=directory): | ||
makedirs(name=directory) | ||
|
||
|
||
def reCreateDirectory(*directories: str) -> None: | ||
"""Delete directories and recreate them | ||
Params: | ||
- *directories (str): The directories to recreate | ||
Returns: | ||
- None | ||
""" | ||
for directory in directories: | ||
if path.exists(path=directory): | ||
removedirs(name=directory) | ||
makedirs(name=directory) |