diff --git a/fin_defs/parse_price.py b/fin_defs/parse_price.py index aa7e712..42513c8 100644 --- a/fin_defs/parse_price.py +++ b/fin_defs/parse_price.py @@ -75,6 +75,8 @@ RE_AMOUNT_SUFFIX_KR = re.compile( flags=re.IGNORECASE, ) +VARIANTS_OF_FREE = frozenset(['free', 'gratis', 'gives væk']) + def parse_price(text: str, default_currency: Asset) -> AssetAmount | None: """ @@ -86,7 +88,9 @@ def parse_price(text: str, default_currency: Asset) -> AssetAmount | None: return text text = str(text).lower().replace('\n', ' ').replace('\t', ' ').strip() - if text == 'free': + if text == '': + return None + if text in VARIANTS_OF_FREE: return AssetAmount(default_currency, Decimal(0)) code, sym, amount_text = None, None, None @@ -102,7 +106,7 @@ def parse_price(text: str, default_currency: Asset) -> AssetAmount | None: elif m := (RE_KR_AMOUNT.fullmatch(text) or RE_AMOUNT_SUFFIX_KR.fullmatch(text)): code, amount_text = 'DKK', m.group('amount') else: - logger.debug('Unknown format: %s', text) + logger.warning('Unknown format: %s', text) return None currency = (