Skip to content

Commit

Permalink
does not add reciept without zip code
Browse files Browse the repository at this point in the history
  • Loading branch information
AarnavGogri committed Oct 18, 2024
1 parent b2e6cb8 commit 32a7860
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions source/backend/resource/resource_receipt.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,23 +189,25 @@ def receipts():
})

# Call the helper function for each purchase item in the receipt
for item in receipt.purchases:
update_price_watch(
zip_code=find_zip_code(data.get('location')),
store_address=parse_address(data.get('location')),
store_name=receipt.store,
item_name=item.get('name'),
item_price=item.get('price'),
current_date=data.get('receipt_date')
)
zip_code = find_zip_code(data.get('location'))
if zip_code:
for item in receipt.purchases:
update_price_watch(
zip_code=zip_code,
store_address=parse_address(data.get('location')),
store_name=receipt.store,
item_name=item.get('name'),
item_price=item.get('price'),
current_date=data.get('receipt_date')
)
return jsonify({'message': 'Receipt uploaded successfully.'}), 201

def parse_address(location):
address_parts = location.split(',')
return address_parts[0]

def find_zip_code(address):
zip_code_regex = re.compile(r"[0-9]{5}(?:-[0-9]{4})?")
zip_code_regex = re.compile(r"[0-9]{5}")
match = zip_code_regex.search(address)
return match.group() if match else None

Expand Down

0 comments on commit 32a7860

Please sign in to comment.