Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add bank of america csv transaction importer #116

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 5 additions & 1 deletion silverstrike/importers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
from . import dkb, dkb_visa, pc_mastercard, volksbank
from . import dkb, dkb_visa, pc_mastercard, volksbank, boa, chase

IMPORTERS = [
dkb,
dkb_visa,
pc_mastercard,
volksbank,
boa,
chase,
]

IMPORTER_NAMES = [
'DKB Giro',
'DKB Visa',
'PC MasterCard',
'Volksbank',
'Bank of America',
'Chase',
]

try:
Expand Down
34 changes: 34 additions & 0 deletions silverstrike/importers/boa.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""
Bank Of America Transactions (CSV) Importer
"""
import csv
import datetime
import logging

from silverstrike.importers.import_statement import ImportStatement

logger = logging.getLogger(__name__)


def import_transactions(csv_path):
lines = []
with open(csv_path) as csv_file:
csviter = csv.reader(csv_file, delimiter=",")
next(csviter) # First line is header
for line in csviter:
try:
transaction_time = datetime.datetime.strptime(line[0], "%m/%d/%Y").date()
lines.append(
ImportStatement(
notes=line[1],
account=line[2],
book_date=transaction_time,
transaction_date=transaction_time,
amount=float(line[4]),
)
)
except ValueError as e:
logger.error("Error" + e)
pass

return lines
35 changes: 35 additions & 0 deletions silverstrike/importers/chase.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""
Chase Transactions (CSV) Importer
"""
import csv
import datetime
import logging

from silverstrike.importers.import_statement import ImportStatement

logger = logging.getLogger(__name__)


def import_transactions(csv_path):
lines = []
with open(csv_path) as csv_file:
csviter = csv.reader(csv_file, delimiter=",")
next(csviter) # First line is header
for line in csviter:
try:
transaction_time = datetime.datetime.strptime(line[0], "%m/%d/%Y").date()
book_date = datetime.datetime.strptime(line[1], "%m/%d/%Y").date()
lines.append(
ImportStatement(
notes="",
account=line[2],
book_date=book_date,
transaction_date=transaction_time,
amount=float(line[5]),
)
)
except ValueError as e:
logger.error("Error" + e)
pass

return lines
5 changes: 5 additions & 0 deletions silverstrike/tests/fixtures/bankofamerica.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Posted Date,Reference Number,Payee,Address,Amount
12/20/2019,427326514,"AUTO PAY","WA ",-142.00
12/19/2019,995870725,"SAMS CLUB","TX ",-114.09
12/18/2019,800053539,"PAYMENT - THANK YOU","",2500.00
12/18/2019,5011550045,"TOM THUMB FUEL","TX ",-30.25
10 changes: 10 additions & 0 deletions silverstrike/tests/fixtures/chase.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Transaction Date,Post Date,Description,Category,Type,Amount
11/26/2019,11/28/2019,TOM THUMB FUEL #0111,Gas,Sale,-41.83
11/26/2019,11/28/2019,TOM THUMB #0111,Groceries,Sale,-76.25
11/26/2019,11/28/2019,TOM THUMB #0111,Groceries,Sale,-124.22
11/19/2019,11/21/2019,KWIK KAR AUTO CENTER,Automotive,Sale,-25.50
11/20/2019,11/21/2019,KROGER #0987,Groceries,Sale,-30.99
11/17/2019,11/19/2019,CALLOWAY'S NURSERY 713,Home,Sale,-34.62
11/18/2019,11/19/2019,Payment Thank You-Mobile,,Payment,1046.34
11/14/2019,11/17/2019,TOM THUMB FUEL #0111,Gas,Sale,-41.33
11/15/2019,11/17/2019,BUY BUY BABY #3000,Home,Return,0.28
16 changes: 16 additions & 0 deletions silverstrike/tests/test_importers.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,22 @@ def test_pc_mastercard(self):
t = transactions[0]
self.assertEqual(t.amount, -40.03)
self.assertEqual(t.book_date, date(2018, 10, 18))

def test_bankofamerica(self):
transactions = importers.boa.import_transactions(
os.path.join(self.base_dir, 'bankofamerica.csv'))
self.assertEqual(len(transactions), 4)
t = transactions[0]
self.assertEqual(t.amount, -142.00)
self.assertEqual(t.book_date, date(2019, 12, 20))

def test_chase(self):
transactions = importers.chase.import_transactions(
os.path.join(self.base_dir, 'chase.csv'))
self.assertEqual(len(transactions), 9)
t = transactions[0]
self.assertEqual(t.amount, -41.83)
self.assertEqual(t.book_date, date(2019, 11, 28))

@skipUnless(hasattr(importers, 'ofx'), 'ofxparse is not installed')
def test_ofx(self):
Expand Down