Skip to content

Commit

Permalink
🐛 fix(logging): increase log file size, may still face issue (#16)
Browse files Browse the repository at this point in the history
* 🧹 chore: savepoint

* 🧹 chore: savepoint

* 🧹 chore: savepoint

* 🧹 chore: savepoint

* 🧹 chore: savepoint

* 🎨 refactor: auto code check

* 🧹 chore: savepoint

* Prepare to switch to original multiprocessing

* Still face like not using the same queue

* Update src/modules/create_pdf.py

Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>

* Update src/modules/create_pdf.py

Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>

* 🧹 chore: savepoint

* Give it a try

* Log in 1 file while multiprocessing

* increase log file size

---------

Co-authored-by: KevinNitroG <[email protected]>
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Mar 12, 2024
1 parent b995540 commit 43aad55
Show file tree
Hide file tree
Showing 20 changed files with 207 additions and 67 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/code-check.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
name: Code Check

concurrency:
cancel-in-progress: true
cancel-in-progress: false
group: code-check

on:
push:
branches:
- main
pull_request:
workflow_dispatch:

Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ repos:
args:
- "--allow-multiple-documents"
- id: trailing-whitespace
exclude: "^(docs/README.md|src/constants.py)"
exclude: "^(docs/README.md|src/constants.py|assets/utils/ascii_banner.txt)"
- id: end-of-file-fixer
- id: debug-statements
# - id: double-quote-string-fixer
Expand Down
6 changes: 3 additions & 3 deletions assets/utils/ascii_banner.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
██╗ ██╗███╗ ██╗██╗ ██╗██╗ ██╗██████╗
██╗ ██╗███╗ ██╗██╗ ██╗██╗ ██╗██████╗
██║ ██║████╗ ██║██║ ██║██║ ██║██╔══██╗
██║ ██║██╔██╗ ██║██║ ██║██║ ██║██████╔╝
╚██╗ ██╔╝██║╚██╗██║██║ ██║██║ ██║██╔══██╗
╚████╔╝ ██║ ╚████║╚██████╔╝███████╗██║██████╔╝
╚═══╝ ╚═╝ ╚═══╝ ╚═════╝ ╚══════╝╚═╝╚═════╝
╚═══╝ ╚═╝ ╚═══╝ ╚═════╝ ╚══════╝╚═╝╚═════╝

██████╗ ██████╗ ██╗ ██╗███╗ ██╗██╗ ██████╗ █████╗ ██████╗ ███████╗██████╗
██████╗ ██████╗ ██╗ ██╗███╗ ██╗██╗ ██████╗ █████╗ ██████╗ ███████╗██████╗
██╔══██╗██╔═══██╗██║ ██║████╗ ██║██║ ██╔═══██╗██╔══██╗██╔══██╗██╔════╝██╔══██╗
██║ ██║██║ ██║██║ █╗ ██║██╔██╗ ██║██║ ██║ ██║███████║██║ ██║█████╗ ██████╔╝
██║ ██║██║ ██║██║███╗██║██║╚██╗██║██║ ██║ ██║██╔══██║██║ ██║██╔══╝ ██╔══██╗
Expand Down
1 change: 1 addition & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ python main.py

## 📓 TODO

- [ ] Logging to file check ⚠️ due to `RotatingFileHandler` on Windows
- [ ] Support more browsers _(inherited from which class?)_
- [ ] Options to enable Multithreading, Multiprocessing
- [ ] Update tool option using command line arguments
Expand Down
15 changes: 10 additions & 5 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

from __future__ import annotations


from pprint import pformat
from multiprocessing import freeze_support
from logging import getLogger
from src import (
Action,
Browser,
Expand All @@ -15,8 +17,8 @@
Login,
PrintIntro,
UserOptions,
ToolLogger,
create_directory,
logger,
pause,
print_title,
)
Expand All @@ -25,6 +27,9 @@

def main() -> None:
"""Main function to run VNULIB Downloader."""
ToolLogger().setup()
logger = getLogger("vnulib_downloader")

PrintIntro()

print_title("USER OPTIONS")
Expand Down Expand Up @@ -56,9 +61,8 @@ def main() -> None:
).action()
logger.debug(msg=f"LINKS OBJECT:\n{pformat(user_options.links)}")

create_directory(DOWNLOAD_DIR, force=False)

print_title("DOWNLOAD")
create_directory(DOWNLOAD_DIR, force=False)
DownloadIMG(
links=user_options.links,
download_directory=DOWNLOAD_DIR,
Expand All @@ -73,9 +77,10 @@ def main() -> None:
print_title("DELETE IMAGES")
CleanIMG(user_options.links, DOWNLOAD_DIR).clean_img()

print_title("END PROGRAM")
pause()


if __name__ == "__main__":
freeze_support() # For pyinstaller to fix multiprocessing in Windows
main()
print_title("END PROGRAM")
pause()
7 changes: 6 additions & 1 deletion src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,9 @@
UserOptions,
setup_argparse,
)
from .utils import create_directory, logger, pause, print_title
from .utils import (
ToolLogger,
create_directory,
pause,
print_title,
)
10 changes: 7 additions & 3 deletions src/bot/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@
from __future__ import annotations

from urllib.parse import parse_qs, urlparse
from logging import getLogger
from selenium.webdriver.chrome.webdriver import WebDriver
from selenium.webdriver.common.by import By
from selenium.webdriver.remote.webelement import WebElement
from .utils import wait_element_visible
from ..modules import Link, LinkFile
from ..utils import datetime_name, logger, slugify
from ..utils import datetime_name, slugify


logger = getLogger("vnulib_downloader")


class Action:
Expand Down Expand Up @@ -150,11 +154,11 @@ def action(self) -> list[Link]:
for link in self.links:
match link.original_type:
case "book":
converted_links.append(self.book_handler(link=link))
logger.info(msg=f'"{link.original_link}": "{link.original_type}"')
converted_links.append(self.book_handler(link=link))
case "preview":
converted_links.append(self.preview_handler(link=link))
logger.info(msg=f'"{link.original_link}": "{link.original_type}"')
converted_links.append(self.preview_handler(link=link))
case "page":
converted_links.append(link)
return converted_links
4 changes: 3 additions & 1 deletion src/bot/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@

import logging
import os
from logging import getLogger
import urllib3
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.webdriver import WebDriver
from webdriver_manager.chrome import ChromeDriverManager
from webdriver_manager.core.logger import set_logger
from src.constants import BROWSER_ARGUMENTS
from ..utils import logger


logger = getLogger("vnulib_downloader")

set_logger(logger)
os.environ["WDM_LOG"] = str(logging.DEBUG)
os.environ["WDM_SSL_VERIFY"] = "0"
Expand Down
5 changes: 4 additions & 1 deletion src/bot/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

from __future__ import annotations

from logging import getLogger
from selenium.webdriver.chrome.webdriver import WebDriver
from selenium.webdriver.common.by import By
from selenium.webdriver.remote.webelement import WebElement
from .utils import wait_element_clickable
from ..constants import LOGIN_URL
from ..utils import logger


logger = getLogger("vnulib_downloader")


class Login:
Expand Down
2 changes: 1 addition & 1 deletion src/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
BUNDLE_DIR = ""


VERSION: str = "1.12"
VERSION: str = "1.13"
AUTHORS: str = "KevinNitroG & NTGNguyen"
BANNER_FILE: str = f"{BUNDLE_DIR}assets/utils/ascii_banner.txt"
with open(BANNER_FILE, encoding="utf-8") as banner_content:
Expand Down
25 changes: 17 additions & 8 deletions src/logging_configuration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,35 @@ formatters:
detail:
"format": "%(asctime)s [%(levelname)-8s] - %(message)s (%(pathname)s:%(lineno)d)"
handlers:
stdout:
stdout_handler:
class: logging.StreamHandler
stream: ext://sys.stdout
formatter: simple
level: INFO
file:
file_handler:
class: logging.FileHandler
formatter: verbose
filename: "log/tool.log"
level: DEBUG
encoding: utf-8
rotating_file_handler: # Problem of RotatingFileHandler: https://python-forum.io/thread-19104.html
class: logging.handlers.RotatingFileHandler
formatter: verbose
filename: "log/tool.log"
maxBytes: 20000 # 2KB
maxBytes: 50000 # 5KB
backupCount: 3
level: DEBUG
encoding: utf-8
delay: false
loggers:
vnulib_downloader:
level: DEBUG
handlers:
- stdout
- file
- stdout_handler
- rotating_file_handler
vnulib_downloader_queue:
level: DEBUG
handlers:
- stdout_handler
- file_handler
propogate: false
root:
level: CRITICAL
propogate: false
5 changes: 4 additions & 1 deletion src/modules/clean_img.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
from __future__ import annotations

import os
from logging import getLogger
from .link_parse import Link
from ..utils import logger


logger = getLogger("vnulib_downloader")


class CleanIMG:
Expand Down
5 changes: 4 additions & 1 deletion src/modules/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@

from os import path
from shutil import copyfile
from logging import getLogger
from ..constants import CONFIG_FILE, CONFIG_SAMPLE_FILE
from ..utils import logger


logger = getLogger("vnulib_downloader")


class Config:
Expand Down
Loading

0 comments on commit 43aad55

Please sign in to comment.