2022-09-05 08:31:12 +00:00
|
|
|
from loguru import logger
|
2022-09-10 17:49:12 +00:00
|
|
|
# import pretty_errors
|
2022-09-05 08:31:12 +00:00
|
|
|
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-12 13:18:21 +00:00
|
|
|
from argparse import ArgumentParser, Namespace
|
2022-09-05 08:31:12 +00:00
|
|
|
import yaml
|
|
|
|
|
2022-09-10 15:40:36 +00:00
|
|
|
import asyncio
|
2022-09-12 13:18:21 +00:00
|
|
|
from courts_scraper.scraper import Scraper
|
2022-09-10 15:40:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
def init_argparser() -> ArgumentParser:
|
|
|
|
argparser = argparse.ArgumentParser(
|
|
|
|
description="List fish in aquarium.",
|
|
|
|
)
|
|
|
|
argparser.add_argument(
|
|
|
|
"--config", "-c",
|
|
|
|
help="Path to the config file",
|
|
|
|
type=pathlib.Path,
|
|
|
|
)
|
|
|
|
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,
|
|
|
|
)
|
2022-09-12 13:18:21 +00:00
|
|
|
argparser.add_argument("--rps", type=int)
|
2022-09-10 15:40:36 +00:00
|
|
|
|
|
|
|
return argparser
|
|
|
|
|
|
|
|
|
|
|
|
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-12 13:18:21 +00:00
|
|
|
scraper_settings = dict()
|
|
|
|
argparser = init_argparser()
|
|
|
|
args = argparser.parse_args()
|
|
|
|
|
|
|
|
if args.config is not None:
|
|
|
|
with open(args.config) as config_file:
|
|
|
|
scraper_settings = yaml.safe_load(config_file)
|
|
|
|
else:
|
|
|
|
scraper_settings["rps"] = args.rps
|
|
|
|
|
|
|
|
with open(args.domains) as domains_file:
|
|
|
|
scraper_settings["domains"] = domains_file.readlines()
|
|
|
|
|
|
|
|
if args.proxy is not None: # Optional argument
|
|
|
|
with open(args.proxy) as proxy_file:
|
|
|
|
scraper_settings["proxy"] = proxy_file.readlines()
|
|
|
|
|
|
|
|
scraper = Scraper(**scraper_settings)
|
2022-09-10 17:49:12 +00:00
|
|
|
await scraper.scrape()
|
2022-09-05 08:31:12 +00:00
|
|
|
|
|
|
|
|
2022-09-10 15:40:36 +00:00
|
|
|
asyncio.run(main())
|