fix rogers parser for new format
This commit is contained in:
@@ -77,7 +77,7 @@ class TransactionParsingFailed(Exception):
|
||||
|
||||
class RogersBankParser(TransactionParser):
|
||||
EXTRACT_RE = re.compile(
|
||||
r"Attempt of \$([0-9,]+\.\d{2}) was made on ([A-z]{3} \d{1,2}, \d{4})[^<]*at ([^<]+) in ([^<]+)." # noqa: E501
|
||||
r"\$([0-9,]+\.\d{2}) on ((Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) [0-9]{2}, [0-9]{4}) on your credit card ending in ([0-9]{4}). Details: ([^.]+)" # noqa: E501
|
||||
)
|
||||
|
||||
def __init__(self, account_id: UUID):
|
||||
@@ -90,17 +90,16 @@ class RogersBankParser(TransactionParser):
|
||||
)
|
||||
|
||||
def extract(self, msg: EmailMessage) -> Optional[Transaction]:
|
||||
content = self.get_content(msg)
|
||||
content = self.strip_html(msg)
|
||||
matches = self.EXTRACT_RE.search(content)
|
||||
if matches is None:
|
||||
raise TransactionParsingFailed("No matches for extraction RE")
|
||||
amount = Decimal(matches[1].replace(",", "")) * -1
|
||||
|
||||
date_raw = matches[2]
|
||||
payee = matches[3]
|
||||
location = matches[4]
|
||||
payee = matches[5]
|
||||
|
||||
if "Rebate" == location and "CashBack" in payee:
|
||||
if "CashBack" in payee:
|
||||
amount = amount * -1
|
||||
|
||||
date = datetime.strptime(date_raw, "%b %d, %Y").date()
|
||||
@@ -109,7 +108,7 @@ class RogersBankParser(TransactionParser):
|
||||
date=date,
|
||||
amount=amount,
|
||||
payee=payee,
|
||||
notes=f"in {location} (via email)",
|
||||
notes="(via email)",
|
||||
imported_id=msg["Message-ID"],
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user