Refactor, add asyncio support
This commit is contained in:
parent
972fe23101
commit
bdfb6ae5c5
82
main.py
82
main.py
|
@ -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
|
||||
|
||||
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())
|
||||
|
||||
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)
|
||||
|
||||
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...")
|
||||
config = load_config()
|
||||
|
||||
|
||||
with open(args["config"]) as f:
|
||||
config = yaml.safe_load(f)
|
||||
config["settings"].update(args)
|
||||
asyncio.run(main())
|
||||
|
|
Reference in a new issue