mirror of
https://github.com/dgtlmoon/changedetection.io.git
synced 2026-09-23 13:56:48 +00:00
WIP
This commit is contained in:
@@ -17,6 +17,7 @@ def construct_blueprint(datastore: ChangeDetectionStore, update_q: PriorityQueue
|
||||
@price_data_follower_blueprint.route("/<string:uuid>/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"))
|
||||
|
||||
|
||||
@@ -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': [],
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -72,7 +72,7 @@
|
||||
<span class="pure-form-message-inline">
|
||||
{% if watch['processor'] == 'text_json_diff' %}
|
||||
Current mode: <strong>Webpage Text/HTML, JSON and PDF changes.</strong><br>
|
||||
<a href="{{url_for('edit_page', uuid=uuid)}}?switch_processor=restock_diff" class="pure-button button-xsmall">Switch to re-stock detection mode.</a>
|
||||
<a href="{{url_for('edit_page', uuid=uuid)}}?switch_processor=restock_diff" class="pure-button button-xsmall">Switch to re-stock & Price detection mode for single product pages</a>
|
||||
{% else %}
|
||||
Current mode: <strong>Re-stock detection.</strong><br>
|
||||
<a href="{{url_for('edit_page', uuid=uuid)}}?switch_processor=text_json_diff" class="pure-button button-xsmall">Switch to Webpage Text/HTML, JSON and PDF changes mode.</a>
|
||||
|
||||
@@ -147,7 +147,7 @@
|
||||
<td class="restock-and-price">
|
||||
{% if watch['processor'] == 'restock_diff' %}
|
||||
{% if watch['restock']['in_stock'] != None %}
|
||||
<span class="restock-label {{'in-stock' if watch['restock']['in_stock'] else 'not-in-stock' }}" title="detecting restock and price">
|
||||
<span class="restock-label {{'in-stock' if watch['restock']['in_stock'] else 'not-in-stock' }}" title="Detecting restock and price">
|
||||
<!-- maybe some object watch['processor'][restock_diff] or.. -->
|
||||
{% if watch['restock']['in_stock'] %} In stock {% else %} Not in stock {% endif %}
|
||||
</span>
|
||||
@@ -156,7 +156,7 @@
|
||||
{% endif %}
|
||||
|
||||
{% if watch['restock']['price'] != None %}
|
||||
<span class="restock-label price {{'in-stock' if watch['restock']['in_stock'] else 'not-in-stock' }}" title="price">
|
||||
<span class="restock-label price {{'in-stock' if watch['restock']['in_stock'] else 'not-in-stock' }}" title="Price">
|
||||
{{ watch['restock']['price'] }} {{ watch['restock']['currency'] }}
|
||||
</span>
|
||||
{% endif %}
|
||||
|
||||
Reference in New Issue
Block a user