From bfc51fedf04e89fcbf942f1d0bfea738d7d129ed Mon Sep 17 00:00:00 2001 From: Jon Michael Aanes Date: Thu, 5 Dec 2024 22:39:44 +0100 Subject: [PATCH] Extra args --- requests_util/__init__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/requests_util/__init__.py b/requests_util/__init__.py index ccefc71..330e175 100644 --- a/requests_util/__init__.py +++ b/requests_util/__init__.py @@ -43,7 +43,7 @@ except ImportError: CACHE_PATH_FROM_HOME = '.local/share/usagi-keiretsu/fin_data/http_cache' -def initialize_session() -> requests.Session: +def initialize_session(extra_cache_args: dict | None = None) -> requests.Session: """Creates Session with or without caching depending upon current capabilities. """ @@ -54,12 +54,14 @@ def initialize_session() -> requests.Session: home = pathlib.Path(os.environ['HOME']) cache_path = home / CACHE_PATH_FROM_HOME cache_path.mkdir(parents=True, exist_ok=True) + extra_cache_args = extra_cache_args or {} session = requests_cache.CachedSession( cache_path, expire_after=datetime.timedelta(days=1), stale_if_error=True, cache_control=False, urls_expire_after={}, + **extra_cache_args, ) else: session = requests.Session()