From 553f6fe7d4b7d91b7c649488c3bd925b28e888ac Mon Sep 17 00:00:00 2001 From: Jon Michael Aanes Date: Thu, 18 Apr 2024 00:02:13 +0200 Subject: [PATCH] Improve behaviour without cfscrape --- personal_data/main.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/personal_data/main.py b/personal_data/main.py index 443e570..8542962 100644 --- a/personal_data/main.py +++ b/personal_data/main.py @@ -150,13 +150,17 @@ STANDARD_HEADERS = { } -class CachedCfScrape(requests_cache.CacheMixin, cfscrape.CloudflareScraper): - pass +if cfscrape: + class CachedCfScrape(requests_cache.CacheMixin, cfscrape.CloudflareScraper): + pass def get_session(cookiejar, *, with_cfscrape: bool) -> requests.Session: assert isinstance(with_cfscrape, bool) - session = CachedCfScrape('web_cache', cookies=cookiejar) + session_class = requests_cache.CachedSession + if cfscrape: + session_class = CachedCfScrape + session = session_class('web_cache', cookies=cookiejar) for cookie in cookiejar: session.cookies.set_cookie(cookie) return session