1
0

Explicit ignore cache
Some checks failed
Test Python / Test (push) Has been cancelled

This commit is contained in:
Jon Michael Aanes 2024-06-03 00:00:01 +02:00
parent cc4b553feb
commit 02763e72b6
Signed by: Jmaa
SSH Key Fingerprint: SHA256:Ab0GfHGCblESJx7JRE4fj4bFy/KRpeLhi41y4pF3sNA
3 changed files with 14 additions and 4 deletions

View File

@ -20,6 +20,9 @@ def parse_arguments():
parser.add_argument( parser.add_argument(
'--loud-sound', action='store_true', dest='trigger_loud_and_annoying_sound', '--loud-sound', action='store_true', dest='trigger_loud_and_annoying_sound',
) )
parser.add_argument(
'--ignore-cache', action='store_true', dest='ignore_cache',
)
return parser.parse_args() return parser.parse_args()
@ -40,6 +43,7 @@ def main():
scraper_filter, scraper_filter,
use_cookiejar=args.cookiejar, use_cookiejar=args.cookiejar,
notification_types=frozenset(notification_types), notification_types=frozenset(notification_types),
ignore_cache = args.ignore_cache,
) )

View File

@ -29,7 +29,7 @@ class FinanceDepoScraper(Scraper):
'account.update_time': depo.updated_time, 'account.update_time': depo.updated_time,
} }
for asset in depo.assets(): for asset in sorted(depo.assets()):
key = f'balance.{asset}' key = f'balance.{asset}'
data_point[key] = depo.get_amount_of_asset(asset) data_point[key] = depo.get_amount_of_asset(asset)

View File

@ -195,9 +195,12 @@ if cfscrape:
pass pass
def get_session(cookiejar, *, with_cfscrape: bool) -> requests.Session: def get_session(cookiejar, *, with_cfscrape: bool, ignore_cache: bool) -> requests.Session:
assert isinstance(with_cfscrape, bool) assert isinstance(with_cfscrape, bool)
session_class = requests_cache.CachedSession session_class = requests_cache.CachedSession
if ignore_cache:
session_class = requests.Session
logger.warn('HTTP cache disabled')
if cfscrape: if cfscrape:
session_class = CachedCfScrape session_class = CachedCfScrape
session = session_class('output/web_cache', cookies=cookiejar) session = session_class('output/web_cache', cookies=cookiejar)
@ -226,7 +229,8 @@ def main(
scraper_filter: frozenset[str], scraper_filter: frozenset[str],
*, *,
use_cookiejar: bool, use_cookiejar: bool,
notification_types: frozenset[notification.NotificationType] = frozenset(), ignore_cache: bool,
notification_types: frozenset[notification.NotificationType],
) -> None: ) -> None:
if use_cookiejar: if use_cookiejar:
cookiejar = browsercookie.firefox() cookiejar = browsercookie.firefox()
@ -239,7 +243,9 @@ def main(
logger.info('No notifications enabled: Notifications will not be sent!') logger.info('No notifications enabled: Notifications will not be sent!')
for scraper_cls in available_scrapers(): for scraper_cls in available_scrapers():
session = get_session(cookiejar, with_cfscrape=scraper_cls.requires_cfscrape()) session = get_session(cookiejar,
with_cfscrape=scraper_cls.requires_cfscrape(),
ignore_cache = ignore_cache)
scraper = scraper_cls(session) scraper = scraper_cls(session)
if scraper_cls.__name__ not in scraper_filter: if scraper_cls.__name__ not in scraper_filter:
continue continue