Skip to content

Commit

Permalink
Handle new coles case
Browse files Browse the repository at this point in the history
  • Loading branch information
Javex committed Nov 10, 2023
1 parent 92cd981 commit 6b788ce
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
12 changes: 10 additions & 2 deletions hotprices_au/sites/coles.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,19 @@ def get_quantity_and_unit(item):
def parse_str_unit(size):
# Try coles-special methods before going to the generic function
size = size.lower()
matched = re.match(r'^.*can (?P<quantity>[0-9]+)(?P<unit>[a-z]+):pack(?P<count>[0-9]+)', size)
matched = re.match(r'^.* (?P<quantity>[0-9]+)(?P<unit>[a-z]+):(pack(?P<count>[0-9]+)|(?P<each>ea))', size)
if matched:
quantity = float(matched.group('quantity'))
unit = matched.group('unit')
count = float(matched.group('count'))
count_match = matched.group('count')
if count_match:
count = float(count_match)
else:
each_str = matched.group('each')
if each_str:
count = 1
else:
raise RuntimeError("Didn't get a count, expected 'each'/'ea'")
quantity *= count
return quantity, unit
else:
Expand Down
6 changes: 6 additions & 0 deletions tests/stores/test_coles.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ def test_get_canonical():
assert can_item['quantity'] == 2250
assert not can_item['isWeighted']

item = get_item(description='SMIRNOFF RED 37.5% VODKA 375ML:EA', quantity=0, isWeighted=False, size='')
can_item = coles.get_canonical(item, today)
assert can_item['unit'] == 'ml'
assert can_item['quantity'] == 375
assert not can_item['isWeighted']

item = get_item(size='180g', ofMeasureUnits='g', quantity=1, isWeighted=False)
can_item = coles.get_canonical(item, today)
assert can_item['unit'] == 'g'
Expand Down

0 comments on commit 6b788ce

Please sign in to comment.