linter &c
This commit is contained in:
23
parsers.py
23
parsers.py
@@ -1,16 +1,18 @@
|
||||
import re
|
||||
from abc import ABC
|
||||
from abc import abstractmethod
|
||||
from datetime import datetime
|
||||
from decimal import Decimal
|
||||
from email.message import EmailMessage
|
||||
from model import Transaction
|
||||
import re
|
||||
from email.message import Message
|
||||
from uuid import UUID
|
||||
from datetime import datetime
|
||||
from logging import debug
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
from model import Transaction
|
||||
|
||||
|
||||
class TransactionParser(ABC):
|
||||
@abstractmethod
|
||||
def match(self, msg: EmailMessage) -> bool:
|
||||
def match(self, msg: Message) -> bool:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
@@ -30,16 +32,19 @@ class RogersBankParser(TransactionParser):
|
||||
def __init__(self, account_id: UUID):
|
||||
self.account_id = account_id
|
||||
|
||||
def match(self, msg: EmailMessage) -> bool:
|
||||
def match(self, msg: Message) -> bool:
|
||||
return (
|
||||
msg["From"] == "Rogers Bank <onlineservices@RogersBank.com>"
|
||||
and msg["Subject"] == "Purchase amount alert"
|
||||
)
|
||||
|
||||
def extract(self, msg: EmailMessage) -> Transaction:
|
||||
matches = RogersBankParser.EXTRACT_RE.search(msg.get_body().as_string())
|
||||
body = msg.get_body()
|
||||
if body is None:
|
||||
raise TransactionParsingFailed("No body of message found")
|
||||
matches = RogersBankParser.EXTRACT_RE.search(body.as_string())
|
||||
if matches is None:
|
||||
return TransactionParsingFailed("No matches for extraction RE")
|
||||
raise TransactionParsingFailed("No matches for extraction RE")
|
||||
amount = Decimal(matches[1])
|
||||
date_raw = matches[2]
|
||||
payee = matches[3]
|
||||
|
||||
Reference in New Issue
Block a user