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

58 lines
1.3 KiB
Python
Raw Normal View History

2023-01-02 00:09:55 +03:00
from __future__ import annotations
import asyncio
import logging
import sys
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())
elif sys.implementation.name == "cpython" and sys.platform in {
2023-01-02 00:09:55 +03:00
"darwin",
"linux",
}:
try:
import uvloop
except ImportError:
pass
else:
uvloop.install()
2023-01-02 09:44:39 +03:00
def configure_logging(console: Console) -> None:
2023-01-02 00:09:55 +03:00
rich.traceback.install(console=console)
logging.basicConfig(
level=logging.INFO,
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-01-02 09:44:39 +03:00
def main() -> None:
set_event_loop_policy()
2023-01-02 00:09:55 +03:00
console = Console()
2023-01-02 09:44:39 +03:00
configure_logging(console)
2023-01-02 00:09:55 +03:00
psc = ProxyScraperChecker.from_ini("config.ini", console=console)
asyncio.run(psc.run())
2023-01-02 09:44:39 +03:00
if __name__ == "__main__":
main()