min/mnax price check

piwheels-rpi-crypto
dgtlmoon 5 months ago
parent cf43852645
commit e756002b9a

@ -549,15 +549,16 @@ class processor_restock_diff_form(processor_text_json_diff_form):
</fieldset>
<fieldset class="pure-group">
{{ render_checkbox_field(form.follow_price_changes) }}
<span class="pure-form-message-inline">Changes in price should trigger a notification.</span>
<span class="pure-form-message-inline">Changes in price should trigger a notification</span>
<span class="pure-form-message-inline">When OFF - only care about restock detection</span>
</fieldset>
<fieldset class="pure-group price-change-minmax">
{{ render_field(form.price_change_min) }}
<span class="pure-form-message-inline">Minimum amount, when the price is below this amount, then a change is triggered.</span>
<span class="pure-form-message-inline">Minimum amount, only trigger a change when the price is less than this amount.</span>
</fieldset>
<fieldset class="pure-group price-change-minmax">
{{ render_field(form.price_change_max) }}
<span class="pure-form-message-inline">Maximum amount, when the price is above this amount, then a change is triggered.</span>
<span class="pure-form-message-inline">Maximum amount, only trigger a change when the price is more than this amount.</span>
</fieldset>
</div>
</fieldset>"""

@ -164,30 +164,26 @@ class perform_site_check(difference_detection_processor):
if watch.get('follow_price_changes') and watch.get('restock'):
price = float(update_obj['restock'].get('price'))
previous_price = float(watch['restock'].get('price'))
# It was different, but negate it further down
if price != previous_price:
changed_detected = True
# Minimum price limit
# Minimum/maximum price limit
if update_obj.get('restock') and update_obj['restock'].get('price') and watch.get('price_change_min'):
logger.debug(
f"{uuid} - Change was detected, Has minimum price limit - 'price_change_min' is '{watch.get('price_change_min')}', price from website is '{update_obj['restock'].get('price', '')}'.")
f"{uuid} - Change was detected, Has minimum price limit - 'price_change_max' is '{watch.get('price_change_max', '')}' 'price_change_min' is '{watch.get('price_change_min', '')}', price from website is '{update_obj['restock'].get('price', '')}'.")
if update_obj['restock'].get('price'):
min_limit = float(watch.get('price_change_min'))
price = float(update_obj['restock'].get('price'))
logger.debug(f"{uuid} after float conversion - Min limit: '{min_limit}' Price: '{price}'")
if price > min_limit:
changed_detected = False
min_limit = float(watch.get('price_change_min', 0))
max_limit = float(watch.get('price_change_max', float('inf'))) # Set to infinity if not provided
# Maximum price limit
if update_obj.get('restock') and update_obj['restock'].get('price') and watch.get('price_change_max'):
logger.debug(
f"{uuid} - Change was detected, Has maximum price limit - 'price_change_max' is '{watch.get('price_change_max')}', price from website is '{update_obj['restock'].get('price', '')}'.")
if update_obj['restock'].get('price'):
max_limit = float(watch.get('price_change_max'))
price = float(update_obj['restock'].get('price'))
logger.debug(f"{uuid} after float conversion - Max limit: '{max_limit}' Price: '{price}'")
if price < max_limit:
changed_detected = False
logger.debug(f"{uuid} after float conversion - Min limit: '{min_limit}' Max limit: '{max_limit}' Price: '{price}'")
if changed_detected:
if price < max_limit and price > min_limit:
changed_detected = False
# Always record the new checksum

@ -122,3 +122,55 @@ def test_itemprop_price_change(client, live_server):
res = client.get(url_for("form_delete", uuid="all"), follow_redirects=True)
assert b'Deleted' in res.data
def test_itemprop_price_minmax_limit(client, live_server):
#live_server_setup(live_server)
test_url = url_for('test_endpoint', _external=True)
set_original_response(props_markup=instock_props[0], price="950.95")
client.post(
url_for("form_quick_watch_add"),
data={"url": test_url, "tags": 'restock tests', 'processor': 'restock_diff'},
follow_redirects=True
)
# A change in price, should trigger a change by default
wait_for_all_checks(client)
res = client.post(
url_for("edit_page", uuid="first"),
data={"follow_price_changes": "y",
"price_change_min": 900.0,
"price_change_max": 1100.10,
"url": test_url,
"tags": "",
"headers": "",
'fetch_backend': "html_requests"
},
follow_redirects=True
)
assert b"Updated watch." in res.data
wait_for_all_checks(client)
client.get(url_for("mark_all_viewed"))
# price changed to something greater than min (900), and less than max (1100).. should be no change
set_original_response(props_markup=instock_props[0], price='1000.45')
client.get(url_for("form_watch_checknow"))
wait_for_all_checks(client)
res = client.get(url_for("index"))
assert b'1000.45' in res.data
assert b'unviewed' not in res.data
# price changed to something LESS than min (900), SHOULD be a change
set_original_response(props_markup=instock_props[0], price='890.45')
res = client.get(url_for("form_watch_checknow"), follow_redirects=True)
assert b'1 watches queued for rechecking.' in res.data
wait_for_all_checks(client)
res = client.get(url_for("index"))
assert b'890.45' in res.data
assert b'unviewed' in res.data
Loading…
Cancel
Save