-
Notifications
You must be signed in to change notification settings - Fork 0
/
transaction.py
50 lines (38 loc) · 1.96 KB
/
transaction.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from enum import Enum
from datetime import datetime
class Transaction(object):
"""Class Representing a single transaction"""
def __init__(self, matcher, bank):
#__metaclass__ = MetaTransaction
self.merchant = matcher.group("merchant").strip()[:-1]
self.date = datetime.strptime(matcher.group("date"), "%d-%b-%y").date()
self.cardNo = matcher.group("cardNo")
self.amount = matcher.group("amount").replace(",","")
self.bankName = bank.name
self.transactionType = bank.transactionType
self.cardType = ""
def __repr__(self):
return "Transaction: {5} -> {0} was spent from {1} card with number {2} at {3} on {4}".format(self.amount, self.cardType, self.cardNo, self.merchant, self.date, self.bankName)
class Pattern(Enum):
CITIBANK_CC = "Rs. (?P<amount>[\d,]+\.\d{2}).*(?P<cardType>card).*(?P<cardNo>\d{4}) on (?P<date>.*) at (?P<merchant>.*?\.)"
CITIBANK_CC_OLD = "Rs (?P<amount>[\d,]+\.\d{2}).*(?P<cardType>Credit).*(?P<cardNo>\d{4}X{8}\d{4}) on (?P<date>.*) at (?P<merchant>.*)"
CITIBANK_DC = "Rs (?P<amount>[\d,]+\.\d{2}).*(?P<cardType>Debit).*(?P<cardNo>\d{4}X{8}\d{4}) on (?P<date>.*) at (?P<merchant>.*)"
class Query(Enum):
CITIBANK_CC = 'from:[email protected] subject:Transaction Confirmation'
CITIBANK_DC = 'from:[email protected] subject:Transaction Confirmation'
class TransactionType(Enum):
CASH = 0
CREDITCARD = 1
DEBITCARD = 2
NETBANKING = 3
class BankDetails:
def __init__(self, name, query, pattern, transType):
self.name = name
self.query = query
self.regexPattern = pattern
self.transactionType = transType
class BankDetails(Enum):
CITIBANK_CC = BankDetails("CITIBANK_CC", Query.CITIBANK_CC, Pattern.CITIBANK_CC, TransactionType.CREDITCARD)
CITIBANK_DC = BankDetails("CITIBANK_DC", Query.CITIBANK_DC, Pattern.CITIBANK_DC, TransactionType.DEBITCARD)
if __name__ == "__main__":
pass