diff --git a/changedetectionio/blueprint/watchlist/templates/watch-overview.html b/changedetectionio/blueprint/watchlist/templates/watch-overview.html index e6ecab17f..eadd7192c 100644 --- a/changedetectionio/blueprint/watchlist/templates/watch-overview.html +++ b/changedetectionio/blueprint/watchlist/templates/watch-overview.html @@ -305,12 +305,20 @@ html[data-darkmode="true"] .watch-tag-list.tag-{{ class_name }} { {%- endif -%} {%- if watch.get('restock') and watch['restock'].get('price') -%} - {%- if watch['restock']['price'] is number -%} - - {{ watch['restock']['price']|format_number_locale if watch['restock'].get('price') else '' }} {{ watch['restock'].get('currency','') }} - - {%- else -%} + {%- set restock = watch['restock'] -%} + {%- set price = restock.get('price') -%} + {%- set cur = restock.get('currency','') -%} + + {%- if price is not none and (price|string)|regex_search('\d') -%} + + {# @todo: make parse_currency/parse_decimal aware of the locale of the actual web page and use that instead changedetectionio/processors/restock_diff/__init__.py #} + {%- if price is number -%}{# It's a number so we can convert it to their locale' #} + {{ price|format_number_locale }} {{ cur }} + {%- else -%}{# It's totally fine if it arrives as something else, the website might be something weird in this field #} + {{ price }} {{ cur }} {%- endif -%} + + {%- endif -%} {%- elif not watch.has_restock_info -%} {{ _('No information') }} {%- endif -%} diff --git a/changedetectionio/flask_app.py b/changedetectionio/flask_app.py index a631208d1..f879e6058 100644 --- a/changedetectionio/flask_app.py +++ b/changedetectionio/flask_app.py @@ -217,9 +217,13 @@ def _jinja2_filter_format_number_locale(value: float) -> str: "Formats for example 4000.10 to the local locale default of 4,000.10" # Format the number with two decimal places (locale format string will return 6 decimal) formatted_value = locale.format_string("%.2f", value, grouping=True) - return formatted_value +@app.template_filter('regex_search') +def _jinja2_filter_regex_search(value, pattern): + import re + return re.search(pattern, str(value)) is not None + @app.template_global('is_checking_now') def _watch_is_checking_now(watch_obj, format="%Y-%m-%d %H:%M:%S"): return worker_pool.is_watch_running(watch_obj['uuid']) diff --git a/changedetectionio/processors/restock_diff/__init__.py b/changedetectionio/processors/restock_diff/__init__.py index 79d8c4927..9eb292360 100644 --- a/changedetectionio/processors/restock_diff/__init__.py +++ b/changedetectionio/processors/restock_diff/__init__.py @@ -31,6 +31,7 @@ class Restock(dict): if standardized_value: # Convert to float + # @todo locale needs to be the locale of the webpage return float(parse_decimal(standardized_value, locale='en')) return None diff --git a/changedetectionio/processors/restock_diff/pure_python_extractor.py b/changedetectionio/processors/restock_diff/pure_python_extractor.py index b46920fd2..4c7f0f280 100644 --- a/changedetectionio/processors/restock_diff/pure_python_extractor.py +++ b/changedetectionio/processors/restock_diff/pure_python_extractor.py @@ -283,4 +283,7 @@ def query_price_availability(extracted_data): if not result.get('availability') and 'availability' in microdata: result['availability'] = microdata['availability'] + # result['price'] could be float or str here, depending on the website, for example it might contain "1,00" commas, etc. + # using something like babel you need to know the locale of the website and even then it can be problematic + # we dont really do anything with the price data so far.. so just accept it the way it comes. return result diff --git a/changedetectionio/tests/test_restock_itemprop.py b/changedetectionio/tests/test_restock_itemprop.py index 1e3288df2..6b314771e 100644 --- a/changedetectionio/tests/test_restock_itemprop.py +++ b/changedetectionio/tests/test_restock_itemprop.py @@ -467,3 +467,38 @@ def test_special_prop_examples(client, live_server, measure_memory_usage, datast assert b'155.55' in res.data delete_all_watches(client) + + +def test_itemprop_as_str(client, live_server, measure_memory_usage, datastore_path): + + test_return_data = f""" +
+ Some initial textWhich is across multiple lines
+ + + + + + + + + """ + + with open(os.path.join(datastore_path, "endpoint-content.txt"), "w") as f: + f.write(test_return_data) + + + test_url = url_for('test_endpoint', _external=True) + + client.post( + url_for("ui.ui_views.form_quick_watch_add"), + data={"url": test_url, "tags": 'restock tests', 'processor': 'restock_diff'}, + follow_redirects=True + ) + + client.get(url_for("ui.form_watch_checknow")) + wait_for_all_checks(client) + + res = client.get(url_for("watchlist.index")) + assert b'767.55' in res.data \ No newline at end of file