Skip to content

Commit

Permalink
Fix woolies parsing issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Javex committed Jan 17, 2024
1 parent 8bbbfa4 commit d947000
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
19 changes: 11 additions & 8 deletions hotprices_au/units.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,18 @@ def parse_str_unit(unit_str):
if matched:
try:
count_group = matched.group('count')
# We might match on 4x4 and not just 4, so we split by x, type case each and then multiply them
if 'x' in count_group:
counts = count_group.split('x')
if count_group is None:
count = 1
else:
counts = [count_group]
counts = [float(c) for c in counts]
count = 1
for count_elem in counts:
count *= count_elem
# We might match on 4x4 and not just 4, so we split by x, type case each and then multiply them
if count_group and 'x' in count_group:
counts = count_group.split('x')
else:
counts = [count_group]
counts = [float(c) for c in counts]
count = 1
for count_elem in counts:
count *= count_elem
except IndexError:
count = 1

Expand Down
5 changes: 5 additions & 0 deletions tests/stores/test_woolies.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ def test_get_canonical():
assert can_item['unit'] == 'ml'
assert can_item['quantity'] == 9000

item = get_item(PackageSize='200ml X Pack')
can_item = woolies.get_canonical(item, today)
assert can_item['unit'] == 'ml'
assert can_item['quantity'] == 200


if __name__ == '__main__':
test_get_canonical()

0 comments on commit d947000

Please sign in to comment.