Files
proxy-scraper-checker/proxy_scraper_checker/__main__.py
T

63 lines
1.6 KiB
Python
Raw Normal View History

2023-01-02 00:09:55 +03:00
from __future__ import annotations
import asyncio
import logging
import sys
2023-02-06 20:59:03 +03:00
from configparser import ConfigParser
2023-01-02 00:09:55 +03:00
import rich.traceback
from rich.console import Console
from rich.logging import RichHandler
2023-01-02 09:44:39 +03:00
from .proxy_scraper_checker import ProxyScraperChecker
2023-01-02 00:09:55 +03:00
def set_event_loop_policy() -> None:
if sys.platform == "win32":
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
2023-02-25 19:31:34 +03:00
elif sys.implementation.name == "cpython" and sys.platform in {"darwin", "linux"}:
2023-01-02 00:09:55 +03:00
try:
import uvloop
except ImportError:
pass
else:
uvloop.install()
2023-02-06 20:59:03 +03:00
def configure_logging(console: Console, *, debug: bool) -> None:
2023-01-02 00:09:55 +03:00
rich.traceback.install(console=console)
logging.basicConfig(
2023-02-06 20:59:03 +03:00
level=logging.DEBUG if debug else logging.INFO,
2023-01-02 00:09:55 +03:00
format="%(message)s",
2023-01-02 13:16:05 +03:00
datefmt="%Y-%m-%d %H:%M:%S",
2023-01-02 09:44:39 +03:00
handlers=(
RichHandler(
2023-01-02 13:16:05 +03:00
console=console,
omit_repeated_times=False,
show_path=False,
rich_tracebacks=True,
2023-01-02 09:44:39 +03:00
),
),
2023-01-02 00:09:55 +03:00
)
2023-02-06 20:59:03 +03:00
def get_config(file: str) -> ConfigParser:
cfg = ConfigParser(interpolation=None)
cfg.read(file, encoding="utf-8")
return cfg
2023-02-21 21:22:47 +03:00
async def main() -> None:
2023-02-06 20:59:03 +03:00
cfg = get_config("config.ini")
2023-01-02 00:09:55 +03:00
console = Console()
2023-02-28 06:48:56 +00:00
configure_logging(console, debug=cfg["General"].getboolean("Debug", False))
2023-01-02 00:09:55 +03:00
2023-02-06 20:59:03 +03:00
psc = ProxyScraperChecker.from_configparser(cfg, console=console)
2023-02-21 21:22:47 +03:00
await psc.run()
2023-01-02 09:44:39 +03:00
if __name__ == "__main__":
2023-02-21 21:22:47 +03:00
set_event_loop_policy()
asyncio.run(main())