Skip to content

Commit

Permalink
Fix running when PSL cache dir doesn't yet exist
Browse files Browse the repository at this point in the history
  • Loading branch information
ghostwords committed Mar 4, 2024
1 parent 6bc4a28 commit 0233f51
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/basedomain.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@ def extract(domain):
cache_dir = os.path.join(tempfile.gettempdir(), "python-tldextract")

# expire PSL cache after one week
elapsed_time = datetime.now() - datetime.fromtimestamp(os.stat(cache_dir).st_mtime)
if elapsed_time >= timedelta(weeks=1):
shutil.rmtree(cache_dir)
try:
mtime = os.stat(cache_dir).st_mtime
except FileNotFoundError:
pass
else:
elapsed_time = datetime.now() - datetime.fromtimestamp(mtime)
if elapsed_time >= timedelta(weeks=1):
shutil.rmtree(cache_dir)

_extract = tldextract.TLDExtract(cache_dir=cache_dir,
include_psl_private_domains=True)
Expand Down

0 comments on commit 0233f51

Please sign in to comment.