def get_base_domain(domain, use_fresh_psl=False):
psl_path = os.path.join(tempdir, "<STR_LIT>")<EOL>def download_psl():<EOL><INDENT>url = "<STR_LIT>"<EOL>headers = {"<STR_LIT>": USER_AGENT}<EOL>fresh_psl = requests.get(url, headers=headers).text<EOL>with open(psl_path, "<STR_LIT:w>", encoding="<STR_LIT:utf-8>") as fresh_psl_file:<EOL><INDENT>fresh_psl_file.write(fresh_psl)<EOL><DEDENT><DEDENT>if use_fresh_psl:<EOL><INDENT>if not os.path.exists(psl_path):<EOL><INDENT>download_psl()<EOL><DEDENT>else:<EOL><INDENT>psl_age = datetime.now() - datetime.fromtimestamp(<EOL>os.stat(psl_path).st_mtime)<EOL>if psl_age > timedelta(hours=<NUM_LIT>):<EOL><INDENT>try:<EOL><INDENT>download_psl()<EOL><DEDENT>except Exception as error:<EOL><INDENT>logger.warning(<EOL>"<STR_LIT>".format(error))<EOL><DEDENT><DEDENT><DEDENT>with open(psl_path, encoding="<STR_LIT:utf-8>") as psl_file:<EOL><INDENT>psl = publicsuffix2.PublicSuffixList(psl_file)<EOL><DEDENT>return psl.get_public_suffix(domain)<EOL><DEDENT>else:<EOL><INDENT>return publicsuffix2.get_public_suffix(domain)<EOL><DEDENT>
Gets the base domain name for the given domain

.. note::
    Results are based on a list of public domain suffixes at
    https://publicsuffix.org/list/public_suffix_list.dat.

Args:
    domain (str): A domain or subdomain
    use_fresh_psl (bool): Download a fresh Public Suffix List

Returns:
    str: The base domain of the given domain