Files
proxy-scraper-checker/proxy_scraper_checker/__main__.py
T
monosansGitHubgithub-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
57696e62e3 Update .pre-commit-config.yaml (#101)
* Update .pre-commit-config.yaml

* Fix

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2023-11-04 09:29:21 +00:00

65 lines
1.6 KiB
Python

from __future__ import annotations
import asyncio
import logging
import sys
from configparser import ConfigParser
import rich.traceback
from rich.console import Console
from rich.logging import RichHandler
from .proxy_scraper_checker import ProxyScraperChecker
def set_event_loop_policy() -> None:
if sys.platform == "win32":
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
elif sys.implementation.name == "cpython" and sys.platform in {
"darwin",
"linux",
}:
try:
import uvloop # noqa: PLC0415
except ImportError:
pass
else:
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
def configure_logging(console: Console, *, debug: bool) -> None:
rich.traceback.install(console=console)
logging.basicConfig(
level=logging.DEBUG if debug else logging.INFO,
format="%(message)s",
datefmt=logging.Formatter.default_time_format,
handlers=(
RichHandler(
console=console,
omit_repeated_times=False,
show_path=False,
rich_tracebacks=True,
),
),
)
def get_config(file: str) -> ConfigParser:
cfg = ConfigParser(interpolation=None)
cfg.read(file, encoding="utf-8")
return cfg
async def main() -> None:
cfg = get_config("config.ini")
console = Console()
configure_logging(console, debug=cfg["General"].getboolean("Debug", False))
await ProxyScraperChecker.from_configparser(cfg, console=console).run()
if __name__ == "__main__":
set_event_loop_policy()
asyncio.run(main())