Skip to content

Commit

Permalink
fix: remove duplicated function
Browse files Browse the repository at this point in the history
  • Loading branch information
raphael0202 committed Sep 26, 2023
1 parent ab733fb commit 25499de
Showing 1 changed file with 3 additions and 37 deletions.
40 changes: 3 additions & 37 deletions app/taxonomy.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,52 +4,18 @@
import cachetools
import requests

from app.config import settings
from app.types import JSONType
from app.utils import get_logger
from app.utils.download import (
download_file,
fetch_etag,
get_file_etag,
http_session,
should_download_file,
)
from app.utils.download import download_file, http_session, should_download_file
from app.utils.io import load_json

DEFAULT_CACHE_DIR = Path("~/.cache/search-a-licious/taxonomy").expanduser()
DEFAULT_CACHE_DIR = settings.taxonomy_cache_dir.expanduser()


logger = get_logger(__name__)


def should_download_file(
url: str, filepath: Path, force_download: bool, download_newer: bool
) -> bool:
"""Return True if the file located at `url` should be downloaded again
based on file Etag.
:param url: the file URL
:param filepath: the file cached location
:param force_download: if True, (re)download the file even if it was
cached, defaults to False
:param download_newer: if True, download the file if a more recent
version is available (based on file Etag)
:return: True if the file should be downloaded again, False otherwise
"""
if filepath.is_file():
if not force_download:
return False

if download_newer:
cached_etag = get_file_etag(filepath)
current_etag = fetch_etag(url)

if cached_etag == current_etag:
# The file is up to date, return cached file path
return False

return True


class TaxonomyNode:
"""A taxonomy element.
Expand Down

0 comments on commit 25499de

Please sign in to comment.