Skip to content

Commit

Permalink
Price and restock scraping - small price fix scraper (#2575)
Browse files Browse the repository at this point in the history
  • Loading branch information
dgtlmoon committed Aug 19, 2024
1 parent bf0d410 commit 932cf15
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions changedetectionio/processors/restock_diff/__init__.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
Expand Down

0 comments on commit 932cf15

Please sign in to comment.