Skip to content

Commit

Permalink
Fix coles parsing error and a counting bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Javex committed Jan 6, 2024
1 parent 54a90ce commit 8bbbfa4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
11 changes: 9 additions & 2 deletions hotprices_au/sites/coles.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,21 @@ def parse_str_unit(size):
matches = [
re.match(r'^.* (?P<quantity>[0-9]+)(?P<unit>[a-z]+):(pack(?P<count>[0-9]+)|(?P<each>ea))', size),
re.match(r'^.* (?P<count>[0-9]+)pk can (?P<quantity>[0-9]+)(?P<unit>[a-z]+)', size),
re.match(r'^.* (?P<quantity>[0-9]+)(?P<unit>[a-z]+) \((?P<count>[0-9]+)pk\)', size),
# re.match(r'^.* (?P<quantity>[0-9]+)(?P<unit>[a-z]+) \(?(?P<count>[0-9]+)pk\)?', size),
re.match(r'^.* (?P<quantity>[0-9]+)(?P<unit>[a-z]+) \(?(?P<count>[0-9]+)pk\)?(:ctn)?(?P<ctn_count>[0-9]+)?', size),
]
for matched in matches:
if matched:
quantity = float(matched.group('quantity'))
unit = matched.group('unit')
count_match = matched.group('count')
if count_match:
try:
ctn_count_match = matched.group('ctn_count')
except IndexError:
ctn_count_match = False
if ctn_count_match:
count = float(ctn_count_match)
elif count_match:
count = float(count_match)
else:
each_str = matched.group('each')
Expand Down
8 changes: 7 additions & 1 deletion tests/stores/test_coles.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,13 @@ def test_get_canonical():
item = get_item(description='MOON DOG FIZZER SELTZER 6% CAN 330ML (10PK):CTN30', quantity=0, isWeighted=False, size='')
can_item = coles.get_canonical(item, today)
assert can_item['unit'] == 'ml'
assert can_item['quantity'] == 3300
assert can_item['quantity'] == 9900
assert not can_item['isWeighted']

item = get_item(description='HARD SOLO CAN 375ML 10PK:CTN30', quantity=0, isWeighted=False, size='')
can_item = coles.get_canonical(item, today)
assert can_item['unit'] == 'ml'
assert can_item['quantity'] == 11250
assert not can_item['isWeighted']

item = get_item(description='SMIRNOFF RED 37.5% VODKA 375ML:EA', quantity=0, isWeighted=False, size='')
Expand Down

0 comments on commit 8bbbfa4

Please sign in to comment.