diff --git a/changedetectionio/blueprint/price_data_follower/__init__.py b/changedetectionio/blueprint/price_data_follower/__init__.py index 89a2fc67..52b941ac 100644 --- a/changedetectionio/blueprint/price_data_follower/__init__.py +++ b/changedetectionio/blueprint/price_data_follower/__init__.py @@ -17,6 +17,7 @@ def construct_blueprint(datastore: ChangeDetectionStore, update_q: PriorityQueue @price_data_follower_blueprint.route("//accept", methods=['GET']) def accept(uuid): datastore.data['watching'][uuid]['track_ldjson_price_data'] = PRICE_DATA_TRACK_ACCEPT + datastore.data['watching'][uuid]['processor'] = 'restock_diff' update_q.put(queuedWatchMetaData.PrioritizedItem(priority=1, item={'uuid': uuid, 'skip_when_checksum_same': False})) return redirect(url_for("index")) diff --git a/changedetectionio/model/Watch.py b/changedetectionio/model/Watch.py index afa3e4d4..883c6a40 100644 --- a/changedetectionio/model/Watch.py +++ b/changedetectionio/model/Watch.py @@ -19,6 +19,8 @@ from changedetectionio.notification import ( default_notification_format_for_watch ) +Restock = {'in_stock': None, 'price': None, 'currency': None} + base_config = { 'body': None, 'browser_steps': [], @@ -58,7 +60,7 @@ base_config = { 'previous_md5': False, 'previous_md5_before_filters': False, # Used for skipping changedetection entirely 'proxy': None, # Preferred proxy connection - 'restock': {'in_stock': None, 'price': None, 'currency': None}, # Restock/price storage + 'restock': Restock, # Restock/price storage 'remote_server_reply': None, # From 'server' reply header 'sort_text_alphabetically': False, 'subtractive_selectors': [], diff --git a/changedetectionio/processors/restock_diff.py b/changedetectionio/processors/restock_diff.py index c9d20ee9..401bfb98 100644 --- a/changedetectionio/processors/restock_diff.py +++ b/changedetectionio/processors/restock_diff.py @@ -6,6 +6,7 @@ from ..html_tools import extract_json_as_string, has_ldjson_product_info from copy import deepcopy from loguru import logger import hashlib +import json import re import urllib3 @@ -38,8 +39,6 @@ def get_itemprop_availability(html_content): # https://schema.org/ItemAvailability Which strings mean we should consider it in stock? # Chewing on random content could throw any kind of exception, best to catch it and move on if possible. - import json - # LD-JSON type value = {'price': None, 'availability': None, 'currency': None} try: @@ -51,9 +50,13 @@ def get_itemprop_availability(html_content): if ld_obj and isinstance(ld_obj, list): ld_obj = ld_obj[0] - - value['price'] = ld_obj.get('price') - value['currency'] = ld_obj['pricecurrency'].upper() if ld_obj.get('pricecurrency') else None + # DOnt know why but it happens.. + if ld_obj.get('pricespecification'): + value['price'] = ld_obj['pricespecification'].get('price') + value['currency'] = ld_obj['pricespecification']['pricecurrency'].upper() if ld_obj['pricespecification'].get('pricecurrency') else None + else: + value['price'] = ld_obj.get('price') + value['currency'] = ld_obj['pricecurrency'].upper() if ld_obj.get('pricecurrency') else None value['availability'] = ld_obj['availability'] if ld_obj.get('availability') else None except Exception as e: @@ -103,7 +106,8 @@ class perform_site_check(difference_detection_processor): raise Exception("Watch no longer exists.") # Unset any existing notification error - update_obj = {'last_notification_error': False, 'last_error': False, 'in_stock': None, 'restock': None} + from changedetectionio.model.Watch import Restock + update_obj = {'last_notification_error': False, 'last_error': False, 'restock': Restock} self.screenshot = self.fetcher.screenshot self.xpath_data = self.fetcher.xpath_data diff --git a/changedetectionio/templates/edit.html b/changedetectionio/templates/edit.html index d10df405..f0fce9c8 100644 --- a/changedetectionio/templates/edit.html +++ b/changedetectionio/templates/edit.html @@ -72,7 +72,7 @@ {% if watch['processor'] == 'text_json_diff' %} Current mode: Webpage Text/HTML, JSON and PDF changes.
- Switch to re-stock detection mode. + Switch to re-stock & Price detection mode for single product pages {% else %} Current mode: Re-stock detection.
Switch to Webpage Text/HTML, JSON and PDF changes mode. diff --git a/changedetectionio/templates/watch-overview.html b/changedetectionio/templates/watch-overview.html index 25b761f0..e5e5fe51 100644 --- a/changedetectionio/templates/watch-overview.html +++ b/changedetectionio/templates/watch-overview.html @@ -147,7 +147,7 @@ {% if watch['processor'] == 'restock_diff' %} {% if watch['restock']['in_stock'] != None %} - + {% if watch['restock']['in_stock'] %} In stock {% else %} Not in stock {% endif %} @@ -156,7 +156,7 @@ {% endif %} {% if watch['restock']['price'] != None %} - + {{ watch['restock']['price'] }} {{ watch['restock']['currency'] }} {% endif %}