Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
Finds recipes and fetches real-time Kroger prices based on user location.
"""
import json
import re
import sys
from itertools import zip_longest
from pathlib import Path
Expand Down Expand Up @@ -49,18 +48,17 @@ def parse_r_list(r_string):
if clean_val.upper() == "N/A" or clean_val.lower() in ["character(0)", "none", ""]:
return result

if clean_val.startswith('c('):
content = re.sub(r'^c\(', '', clean_val)
content = re.sub(r'\)$', '', content)
parts = re.findall(r'"([^"]*)"', content)
result = [p.strip() for p in parts if p.strip()]
if not '.' in clean_val:
result = [p.strip() for p in clean_val.split(',') if p.strip()]
elif ", http" in clean_val:
parts = clean_val.split(", http")
result = [parts[0].strip()] + ["http" + p.strip() for p in parts[1:]]
elif clean_val.startswith('http'):
result = [clean_val]
else:
result = [p.strip() for p in clean_val.split(',') if p.strip()]
if "., " in clean_val:
clean_val = clean_val.replace("., ", ". ")
result = [p.strip() for p in clean_val.split('.') if p.strip()]

return result

Expand Down
2 changes: 1 addition & 1 deletion tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class TestCookingHelper(unittest.TestCase):

def test_parse_r_list_valid(self):
"""Test parsing a standard R-style character vector string."""
r_string = 'c("Butter", "Sugar", "Flour")'
r_string = 'Butter, Sugar, Flour'
expected = ["Butter", "Sugar", "Flour"]
self.assertEqual(parse_r_list(r_string), expected)

Expand Down
Loading