Restock - Threshold change since "first check" was working really as "since last check", update UI, tests, field name.
Build and push containers / metadata (push) Has been cancelled
Build and push containers / build-push-containers (push) Has been cancelled
Publish Python 🐍distribution 📦 to PyPI and TestPyPI / Build distribution 📦 (push) Has been cancelled
ChangeDetection.io App Test / lint-code (push) Has been cancelled
ChangeDetection.io App Test / lint-translations (push) Has been cancelled
ChangeDetection.io App Test / lint-template-i18n (push) Has been cancelled
Publish Python 🐍distribution 📦 to PyPI and TestPyPI / Test the built package works basically. (push) Has been cancelled
Publish Python 🐍distribution 📦 to PyPI and TestPyPI / Publish Python 🐍 distribution 📦 to PyPI (push) Has been cancelled
ChangeDetection.io App Test / test-application-3-10 (push) Has been cancelled
ChangeDetection.io App Test / test-application-3-11 (push) Has been cancelled
ChangeDetection.io App Test / test-application-3-12 (push) Has been cancelled
ChangeDetection.io App Test / test-application-3-13 (push) Has been cancelled
ChangeDetection.io App Test / test-application-3-14 (push) Has been cancelled

This commit is contained in:
dgtlmoon
2026-06-18 12:01:41 +02:00
committed by GitHub
parent f58d004070
commit 24da66f92c
33 changed files with 105 additions and 64 deletions
@@ -564,10 +564,15 @@ class perform_site_check(difference_detection_processor):
# Main detection method
fetched_md5 = None
# store original price if not set
if itemprop_availability and itemprop_availability.get('price') and not itemprop_availability.get('original_price'):
itemprop_availability['original_price'] = itemprop_availability.get('price')
update_obj['restock']["original_price"] = itemprop_availability.get('price')
# Record this check's price as 'last_price'. The freshly scraped itemprop never carries
# last_price, so this is (re)set on every check - i.e. last_price always holds the price
# from the most recent check, and at comparison time below it is the PREVIOUS check's price.
if itemprop_availability and itemprop_availability.get('price') and not itemprop_availability.get('last_price'):
itemprop_availability['last_price'] = itemprop_availability.get('price')
update_obj['restock']["last_price"] = itemprop_availability.get('price')
logger.debug(
f"{watch.get('uuid')} Updating price - setting 'last_price' to '{itemprop_availability.get('price')}' "
f"(previously stored 'last_price' was '{(watch.get('restock') or {}).get('last_price')}'). ")
if not self.fetcher.instock_data and not itemprop_availability.get('availability') and not itemprop_availability.get('price'):
raise ProcessorException(
@@ -617,9 +622,13 @@ class perform_site_check(difference_detection_processor):
if restock_settings.get('follow_price_changes') and watch.get('restock') and update_obj.get('restock') and update_obj['restock'].get('price'):
price = float(update_obj['restock'].get('price'))
# Default to current price if no previous price found
if watch['restock'].get('original_price'):
previous_price = float(watch['restock'].get('original_price'))
# Compare against last_price (the price from the previous check)
if watch['restock'].get('last_price'):
previous_price = float(watch['restock'].get('last_price'))
logger.debug(
f"{watch.get('uuid')} Comparing NEW price '{price}' against stored 'last_price' '{previous_price}' "
f"(watch's stored current price was '{(watch.get('restock') or {}).get('price')}') -> "
f"price {'CHANGED' if price != previous_price else 'unchanged'}")
# It was different, but negate it further down
if price != previous_price:
changed_detected = True
@@ -642,11 +651,14 @@ class perform_site_check(difference_detection_processor):
else:
logger.trace(f"{watch.get('uuid')} {price} is between {min_limit} and {max_limit}, continuing normal comparison")
# Price comparison by %
if watch['restock'].get('original_price') and changed_detected and restock_settings.get('price_change_threshold_percent'):
previous_price = float(watch['restock'].get('original_price'))
# Price comparison by % - against last_price (the previous check's price)
if watch['restock'].get('last_price') and changed_detected and restock_settings.get('price_change_threshold_percent'):
previous_price = float(watch['restock'].get('last_price'))
pc = float(restock_settings.get('price_change_threshold_percent'))
change = abs((price - previous_price) / previous_price * 100)
logger.debug(
f"{watch.get('uuid')} % threshold check - comparing NEW price '{price}' against stored "
f"'last_price' '{previous_price}' = {change:.3f}% change (threshold {pc}%)")
if change and change <= pc:
logger.debug(f"{watch.get('uuid')} Override change-detected to FALSE because % threshold ({pc}%) was {change:.3f}%")
changed_detected = False