Skip to content

Commit 55cf0f6

Browse files
committed
Update process-amex-expenses to use regex instead of literals
1 parent eb2836f commit 55cf0f6

File tree

1 file changed

+14
-25
lines changed

1 file changed

+14
-25
lines changed

scripts/process-amex-expenses.py

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,22 @@
1515
import argparse
1616
import re
1717
import sys
18-
from typing import Iterable
18+
1919

2020
import pandas as pd
2121

2222

23-
GROCERY_KEYWORDS: Iterable[str] = (
24-
# Common grocery chains & patterns (extend as needed)
25-
"SAVE ON",
26-
"SAVE-ON",
27-
"SAVEON",
28-
"WHOLE FOODS",
29-
"WHOLEFOODS",
30-
"SAFEWAY",
31-
"NO FRILLS",
32-
"NOFRILLS",
33-
"REAL CANADIAN SUPERSTORE",
34-
"SUPERSTORE",
35-
"THRIFTY FOODS",
36-
"THRIFTY",
37-
"WALMART SUPERCENTER",
38-
"WALMART SUPERCENTRE",
39-
"COSTCO WHOLESALE",
40-
"CHOICES MARKETS",
41-
"URBAN FARE",
42-
"IGA",
43-
)
23+
# Regex patterns for grocery stores
24+
GROCERY_PATTERNS = [
25+
re.compile(r"\bSAVE[-\s]?ON\b", re.IGNORECASE),
26+
re.compile(r"\bWHOLE[-\s]?FOODS\b", re.IGNORECASE),
27+
re.compile(r"\bSAFEWAY\b", re.IGNORECASE),
28+
re.compile(r"\bNO[-\s]?FRILLS\b", re.IGNORECASE),
29+
re.compile(r"\bSUPERSTORE\b", re.IGNORECASE),
30+
re.compile(r"\bTHRIFTY\b", re.IGNORECASE),
31+
re.compile(r"\bWALMART\b", re.IGNORECASE),
32+
re.compile(r"\b7\sELEVEN\b", re.IGNORECASE),
33+
]
4434

4535
TAYLOR_NAME = "TAYLOR"
4636
ANVITA_NAME = "ANVITA"
@@ -61,11 +51,10 @@ def clean_description(desc: str) -> str:
6151

6252

6353
def is_grocery(merchant: str) -> bool:
64-
"""Heuristic: check if the cleaned description contains a known grocery keyword."""
54+
"""Check if the description matches any grocery store pattern."""
6555
if not isinstance(merchant, str):
6656
return False
67-
u = merchant.upper()
68-
return any(k in u for k in GROCERY_KEYWORDS)
57+
return any(pattern.search(merchant) for pattern in GROCERY_PATTERNS)
6958

7059

7160
def main():

0 commit comments

Comments
 (0)