2022-09-05 08:31:12 +00:00
|
|
|
from loguru import logger
|
|
|
|
import pretty_errors
|
|
|
|
from colorama import Fore, Back, Style, init
|
2022-09-07 18:00:02 +00:00
|
|
|
|
|
|
|
import pathlib
|
2022-09-10 15:40:36 +00:00
|
|
|
import sys
|
|
|
|
from sys import platform
|
|
|
|
|
2022-09-05 08:31:12 +00:00
|
|
|
import argparse
|
2022-09-10 15:40:36 +00:00
|
|
|
from argparse import ArgumentParser
|
2022-09-05 08:31:12 +00:00
|
|
|
import yaml
|
|
|
|
|
2022-09-10 15:40:36 +00:00
|
|
|
import asyncio
|
|
|
|
from scraper import Scraper
|
|
|
|
|
|
|
|
|
|
|
|
def init_argparser() -> ArgumentParser:
|
|
|
|
argparser = argparse.ArgumentParser(
|
|
|
|
description="List fish in aquarium.",
|
|
|
|
argument_default=argparse.SUPPRESS
|
|
|
|
)
|
|
|
|
argparser.add_argument(
|
|
|
|
"--config", "-c",
|
|
|
|
help="Path to the config file",
|
|
|
|
type=pathlib.Path,
|
|
|
|
default="config.yaml",
|
|
|
|
)
|
|
|
|
argparser.add_argument(
|
|
|
|
"--domains", "-d",
|
|
|
|
help="Path to the domains file",
|
|
|
|
type=pathlib.Path,
|
|
|
|
)
|
|
|
|
argparser.add_argument(
|
|
|
|
"--proxy", "-p",
|
|
|
|
help="Path to the proxy file",
|
|
|
|
type=pathlib.Path,
|
|
|
|
)
|
|
|
|
argparser.add_argument("--rps_min", help="", type=int)
|
|
|
|
argparser.add_argument("--rps_max", help="", type=int)
|
|
|
|
|
|
|
|
return argparser
|
|
|
|
|
|
|
|
|
|
|
|
def load_config() -> dict:
|
|
|
|
argparser = init_argparser()
|
|
|
|
args = vars(argparser.parse_args())
|
2022-09-05 08:31:12 +00:00
|
|
|
|
2022-09-10 15:40:36 +00:00
|
|
|
with open(args["config"]) as f:
|
|
|
|
config = yaml.safe_load(f)
|
|
|
|
config["settings"].update(args)
|
2022-09-05 08:31:12 +00:00
|
|
|
|
2022-09-10 15:40:36 +00:00
|
|
|
# Remove config path to pass config values to the Scraper
|
|
|
|
config["settings"].pop("config")
|
|
|
|
return config
|
2022-09-07 18:00:02 +00:00
|
|
|
|
2022-09-05 08:31:12 +00:00
|
|
|
|
2022-09-10 15:40:36 +00:00
|
|
|
async def main():
|
|
|
|
logger.add("project.log")
|
|
|
|
logger.info("Starting...")
|
2022-09-05 08:31:12 +00:00
|
|
|
|
2022-09-10 15:40:36 +00:00
|
|
|
if platform != "linux":
|
|
|
|
logger.critical("""\nNot for windows, run only on GNU/Linux!\n""")
|
|
|
|
input()
|
|
|
|
sys.exit(1)
|
2022-09-05 08:31:12 +00:00
|
|
|
|
2022-09-10 15:40:36 +00:00
|
|
|
config = load_config()
|
2022-09-10 15:42:43 +00:00
|
|
|
scraper = Scraper(**config["settings"])
|
2022-09-05 08:31:12 +00:00
|
|
|
|
|
|
|
|
2022-09-10 15:40:36 +00:00
|
|
|
asyncio.run(main())
|