Fixing data problem

pull/2041/head
dgtlmoon 6 months ago
parent 5f3ec2663a
commit 9629b89afc

@ -4,18 +4,28 @@ import uuid
from changedetectionio import strtobool from changedetectionio import strtobool
from changedetectionio.notification import default_notification_format_for_watch from changedetectionio.notification import default_notification_format_for_watch
class Restock(dict): class Restock(dict):
# @todo some setter to handle weird prices like "00,01" etc?
default_values = {'in_stock': None, 'price': None, 'currency': None, 'original_price': None}
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
# Define default values
default_values = {
'in_stock': None,
'price': None,
'currency': None,
'original_price': None
}
# Initialize the dictionary with default values
super().__init__(default_values)
self.default_values.update(dict(*args, **kwargs)) # Update with any provided positional arguments (dictionaries)
super().__init__(self.default_values.copy()) if args:
if len(args) == 1 and isinstance(args[0], dict):
self.update(args[0])
else:
raise ValueError("Only one positional argument of type 'dict' is allowed")
if not self.get('original_price'): # Update with keyword arguments
self['original_price'] = self.get('price') self.update(kwargs)
class watch_base(dict): class watch_base(dict):

@ -286,3 +286,4 @@ def test_data_sanity(client, live_server):
res = client.get(url_for("index")) res = client.get(url_for("index"))
assert str(res.data.decode()).count("950.95") == 1, "Price should only show once (for the watch added, no other watches yet)" assert str(res.data.decode()).count("950.95") == 1, "Price should only show once (for the watch added, no other watches yet)"

@ -145,7 +145,7 @@ def live_server_setup(live_server):
@live_server.app.route('/test-endpoint2') @live_server.app.route('/test-endpoint2')
def test_endpoint2(): def test_endpoint2():
return "some basic content" return "<html><body>some basic content</body></html>"
@live_server.app.route('/test-endpoint') @live_server.app.route('/test-endpoint')
def test_endpoint(): def test_endpoint():

Loading…
Cancel
Save