Skip to content

Commit

Permalink
fix: use global rich.Console object
Browse files Browse the repository at this point in the history
  • Loading branch information
monosans committed Nov 6, 2024
1 parent 48ffa9a commit 6d2ae4f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
6 changes: 3 additions & 3 deletions proxy_scraper_checker/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@

from . import logs

_console, _logs_listener = logs.configure()
_logs_listener = logs.configure()

import asyncio
import logging
import sys
from typing import TYPE_CHECKING

import aiofiles
import rich
from aiohttp import ClientSession, TCPConnector
from rich.progress import BarColumn, MofNCompleteColumn, Progress, TextColumn
from rich.table import Table
Expand Down Expand Up @@ -113,7 +114,6 @@ async def main() -> None:
TextColumn("[green]{task.fields[col2]}"),
BarColumn(),
MofNCompleteColumn(),
console=_console,
transient=True,
) as progress:
scrape = scraper.scrape_all(
Expand Down Expand Up @@ -147,7 +147,7 @@ async def main() -> None:
if settings.check_website:
storage.remove_unchecked()
count_after_checking = storage.get_count()
_console.print(
rich.print(
get_summary_table(
before=count_before_checking, after=count_after_checking
)
Expand Down
9 changes: 2 additions & 7 deletions proxy_scraper_checker/logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,20 @@
if TYPE_CHECKING:
from typing import Any

from rich.console import Console


def configure() -> tuple[Console, logging.handlers.QueueListener]:
def configure() -> logging.handlers.QueueListener:
log_queue: queue.Queue[Any] = queue.Queue()

logging.root.setLevel(logging.INFO)
logging.root.addHandler(logging.handlers.QueueHandler(log_queue))

# Start logging before importing rich for the first time
from rich.console import Console # noqa: PLC0415
from rich.logging import RichHandler # noqa: PLC0415

console = Console()
stream_handler = RichHandler(
console=console,
omit_repeated_times=False,
show_path=False,
log_time_format=logging.Formatter.default_time_format,
)

return console, logging.handlers.QueueListener(log_queue, stream_handler)
return logging.handlers.QueueListener(log_queue, stream_handler)

0 comments on commit 6d2ae4f

Please sign in to comment.