Refactor, add asyncio support

This commit is contained in:
riot 2022-09-10 18:40:36 +03:00
parent 972fe23101
commit bdfb6ae5c5

92
main.py
View file

@ -3,43 +3,67 @@ import pretty_errors
from colorama import Fore, Back, Style, init
import pathlib
import argparse
import yaml
import sys
from sys import platform
import argparse
from argparse import ArgumentParser
import yaml
if platform != "linux":
logger.critical("""\nNot for windows, run only on GNU/Linux!\n""")
input()
sys.exit(1)
parser = argparse.ArgumentParser(
description="List fish in aquarium.",
argument_default=argparse.SUPPRESS
)
parser.add_argument(
"--config", "-c",
help="Path to the config file",
type=pathlib.Path,
default="config.yaml",
)
parser.add_argument(
"--proxy", "-p",
help="Path to the proxy file",
type=pathlib.Path
)
parser.add_argument("--rtc_min", help="", type=int)
parser.add_argument("--rtc_max", help="", type=int)
args = vars(parser.parse_args())
logger.add("project.log")
logger.info("Starting...")
import asyncio
from scraper import Scraper
with open(args["config"]) as f:
config = yaml.safe_load(f)
config["settings"].update(args)
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())
with open(args["config"]) as f:
config = yaml.safe_load(f)
config["settings"].update(args)
# Remove config path to pass config values to the Scraper
config["settings"].pop("config")
return config
async def main():
logger.add("project.log")
logger.info("Starting...")
if platform != "linux":
logger.critical("""\nNot for windows, run only on GNU/Linux!\n""")
input()
sys.exit(1)
config = load_config()
asyncio.run(main())