if league.save_data:
        if not os.path.exists(file_dir):
            os.makedirs(file_dir)

        with open(file_path, "w", encoding="utf-8") as data_out:
            data_out.write(html_soup.prettify())

    return html_soup


def patch_http_connection_pool(**constructor_kwargs):
    """This allows you to override the default parameters of the HTTPConnectionPool constructor. For example, to
    increase the pool size to fix problems with "HttpConnectionPool is full, discarding connection" call this function
    with maxsize=16 (or whatever size you want to give to the connection pool).
    """
    class MyHTTPSConnectionPool(connectionpool.HTTPSConnectionPool):
        def __init__(self, *args, **kwargs):
            kwargs.update(constructor_kwargs)
            super(MyHTTPSConnectionPool, self).__init__(*args, **kwargs)

    poolmanager.pool_classes_by_scheme['https'] = MyHTTPSConnectionPool


if __name__ == "__main__":

    local_config = AppConfigParser()
    local_config.read("../config.ini")
    local_current_nfl_week = get_current_nfl_week(config=local_config,
                                                  dev_offline=False)
    print(local_current_nfl_week)
def get_valid_config(config_file="config.ini"):
    config = AppConfigParser()

    root_directory = Path(__file__).parent.parent

    config_file_path = root_directory / Path(config_file)

    # set local config file (check for existence and access, stop app if does not exist or cannot access)
    if config_file_path.is_file():
        if os.access(config_file_path, mode=os.R_OK):
            logger.debug(
                "Configuration file \"config.ini\" available. Running Fantasy Football Metrics Weekly Report app..."
            )
            config_template = AppConfigParser()
            config_template.read(root_directory / "EXAMPLE-config.ini")
            config.read(config_file_path)

            if not set(config_template.sections()).issubset(
                    set(config.sections())):
                missing_sections = []
                for section in config_template.sections():
                    if section not in config.sections():
                        missing_sections.append(section)

                logger.error(
                    "Your local \"config.ini\" file is missing the following sections:\n\n{0}\n\n"
                    "Please update your \"config.ini\" with the above sections from \"EXAMPLE-config.ini\" "
                    "and try again.".format(", ".join(missing_sections)))
                sys.exit("...run aborted.")
            else:
                logger.debug(
                    "All required local \"config.ini\" sections present.")

            config_map = defaultdict(set)
            for section in config.sections():
                section_keys = set()
                for (k, v) in config.items(section):
                    section_keys.add(k)
                config_map[section] = section_keys

            missing_keys_map = defaultdict(set)
            for section in config_template.sections():
                if section in config.sections():
                    for (k, v) in config_template.items(section):
                        if k not in config_map.get(section):
                            missing_keys_map[section].add(k)

            if missing_keys_map:
                missing_keys_str = ""
                for section, keys in missing_keys_map.items():
                    missing_keys_str += "Section: {0}\n".format(section)
                    for key in keys:
                        missing_keys_str += "  {0}\n".format(key)
                    missing_keys_str += "\n"
                missing_keys_str = missing_keys_str.strip()

                logger.error(
                    "Your local \"config.ini\" file is  missing the following keys (from their respective "
                    "sections):\n\n{0}\n\nPlease update your \"config.ini\" with the above keys from "
                    "\"EXAMPLE-config.ini\" and try again.".format(
                        missing_keys_str))

                sys.exit("...run aborted.")
            else:
                logger.debug("All required local \"config.ini\" keys present.")

            return config
        else:
            logger.error(
                "Unable to access configuration file \"config.ini\". Please check that file permissions are properly set."
            )
            sys.exit("...run aborted.")
    else:
        logger.debug("Configuration file \"config.ini\" not found.")
        create_config = input(
            "{2}Configuration file \"config.ini\" not found. {1}Do you wish to create one? {0}({1}y{0}/{2}n{0}) -> {3}"
            .format(Fore.YELLOW, Fore.GREEN, Fore.RED, Style.RESET_ALL))
        if create_config == "y":
            return create_config_from_template(config, root_directory,
                                               config_file_path)
        if create_config == "n":
            logger.error(
                "Configuration file \"config.ini\" not found. Please make sure that it exists in project root directory."
            )
            sys.exit("...run aborted.")
        else:
            logger.warning("Please only select \"y\" or \"n\".")
            time.sleep(0.25)
            get_valid_config(config_file)
import os
import sys
from utils.app_config_parser import AppConfigParser

module_dir = os.path.dirname(os.path.dirname(__file__))
sys.path.append(module_dir)

from calculate.bad_boy_stats import BadBoyStats
from calculate.beef_stats import BeefStats
from calculate.covid_risk import CovidRisk

test_data_dir = os.path.join(module_dir, "tests")
if not os.path.exists(test_data_dir):
    os.makedirs(test_data_dir)

config = AppConfigParser()
config.read(
    os.path.join(os.path.dirname(os.path.dirname(__file__)), "config.ini"))

player_first_name = "Dion"
player_last_name = "Lewis"
player_full_name = "{0} {1}".format(player_first_name, player_last_name)
player_team_abbr = "PHI"
player_position = "RB"


def test_bad_boy_init():
    bad_boy_stats = BadBoyStats(data_dir=test_data_dir,
                                save_data=True,
                                dev_offline=False,
                                refresh=True)