From 932cf15e1ea2df3f0b4cdae137a5455019fea718 Mon Sep 17 00:00:00 2001 From: dgtlmoon Date: Mon, 19 Aug 2024 15:47:19 +0200 Subject: [PATCH] Price and restock scraping - small price fix scraper (#2575) --- .../processors/restock_diff/__init__.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/changedetectionio/processors/restock_diff/__init__.py b/changedetectionio/processors/restock_diff/__init__.py index 1aeca8af1c2..3d472beece0 100644 --- a/changedetectionio/processors/restock_diff/__init__.py +++ b/changedetectionio/processors/restock_diff/__init__.py @@ -1,11 +1,12 @@ +from babel.numbers import parse_decimal from changedetectionio.model.Watch import model as BaseWatch +from typing import Union import re -from babel.numbers import parse_decimal class Restock(dict): - def parse_currency(self, raw_value: str) -> float: + def parse_currency(self, raw_value: str) -> Union[float, None]: # Clean and standardize the value (ie 1,400.00 should be 1400.00), even better would be store the whole thing as an integer. standardized_value = raw_value @@ -21,8 +22,11 @@ def parse_currency(self, raw_value: str) -> float: # Remove any non-numeric characters except for the decimal point standardized_value = re.sub(r'[^\d.-]', '', standardized_value) - # Convert to float - return float(parse_decimal(standardized_value, locale='en')) + if standardized_value: + # Convert to float + return float(parse_decimal(standardized_value, locale='en')) + + return None def __init__(self, *args, **kwargs): # Define default values