1
0

Free stuff must be correctly marked
Some checks failed
Python Ruff Code Quality / ruff (push) Failing after 30s
Run Python tests (through Pytest) / Test (push) Failing after 25s
Verify Python project can be installed, loaded and have version checked / Test (push) Successful in 22s

This commit is contained in:
Jon Michael Aanes 2025-05-26 23:57:33 +02:00
parent fd3fd337b9
commit 9df5d38792

View File

@ -75,6 +75,8 @@ RE_AMOUNT_SUFFIX_KR = re.compile(
flags=re.IGNORECASE, flags=re.IGNORECASE,
) )
VARIANTS_OF_FREE = frozenset(['free', 'gratis', 'gives væk'])
def parse_price(text: str, default_currency: Asset) -> AssetAmount | None: 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 return text
text = str(text).lower().replace('\n', ' ').replace('\t', ' ').strip() 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)) return AssetAmount(default_currency, Decimal(0))
code, sym, amount_text = None, None, None 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)): elif m := (RE_KR_AMOUNT.fullmatch(text) or RE_AMOUNT_SUFFIX_KR.fullmatch(text)):
code, amount_text = 'DKK', m.group('amount') code, amount_text = 'DKK', m.group('amount')
else: else:
logger.debug('Unknown format: %s', text) logger.warning('Unknown format: %s', text)
return None return None
currency = ( currency = (