1
0

Extra args
All checks were successful
Python Ruff Code Quality / ruff (push) Successful in 23s
Run Python tests (through Pytest) / Test (push) Successful in 26s
Verify Python project can be installed, loaded and have version checked / Test (push) Successful in 22s

This commit is contained in:
Jon Michael Aanes 2024-12-05 22:39:44 +01:00
parent 6c983780bc
commit bfc51fedf0
Signed by: Jmaa
SSH Key Fingerprint: SHA256:Ab0GfHGCblESJx7JRE4fj4bFy/KRpeLhi41y4pF3sNA

View File

@ -43,7 +43,7 @@ except ImportError:
CACHE_PATH_FROM_HOME = '.local/share/usagi-keiretsu/fin_data/http_cache' 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 """Creates Session with or without caching depending upon current
capabilities. capabilities.
""" """
@ -54,12 +54,14 @@ def initialize_session() -> requests.Session:
home = pathlib.Path(os.environ['HOME']) home = pathlib.Path(os.environ['HOME'])
cache_path = home / CACHE_PATH_FROM_HOME cache_path = home / CACHE_PATH_FROM_HOME
cache_path.mkdir(parents=True, exist_ok=True) cache_path.mkdir(parents=True, exist_ok=True)
extra_cache_args = extra_cache_args or {}
session = requests_cache.CachedSession( session = requests_cache.CachedSession(
cache_path, cache_path,
expire_after=datetime.timedelta(days=1), expire_after=datetime.timedelta(days=1),
stale_if_error=True, stale_if_error=True,
cache_control=False, cache_control=False,
urls_expire_after={}, urls_expire_after={},
**extra_cache_args,
) )
else: else:
session = requests.Session() session = requests.Session()