From 34ee9b581253934b94195c3c4e455954b52d8cbc Mon Sep 17 00:00:00 2001 From: Robin <> Date: Sat, 21 Dec 2019 20:50:03 -0600 Subject: [PATCH 1/2] add bank of america csv transaction importer --- silverstrike/importers/__init__.py | 4 ++- silverstrike/importers/boa.py | 34 +++++++++++++++++++ silverstrike/tests/fixtures/bankofamerica.csv | 5 +++ silverstrike/tests/test_importers.py | 8 +++++ 4 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 silverstrike/importers/boa.py create mode 100644 silverstrike/tests/fixtures/bankofamerica.csv diff --git a/silverstrike/importers/__init__.py b/silverstrike/importers/__init__.py index 76d6a250..e260c7fc 100644 --- a/silverstrike/importers/__init__.py +++ b/silverstrike/importers/__init__.py @@ -1,10 +1,11 @@ -from . import dkb, dkb_visa, pc_mastercard, volksbank +from . import dkb, dkb_visa, pc_mastercard, volksbank, boa IMPORTERS = [ dkb, dkb_visa, pc_mastercard, volksbank, + boa, ] IMPORTER_NAMES = [ @@ -12,6 +13,7 @@ 'DKB Visa', 'PC MasterCard', 'Volksbank', + 'Bank of America' ] try: diff --git a/silverstrike/importers/boa.py b/silverstrike/importers/boa.py new file mode 100644 index 00000000..4a814e97 --- /dev/null +++ b/silverstrike/importers/boa.py @@ -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 \ No newline at end of file diff --git a/silverstrike/tests/fixtures/bankofamerica.csv b/silverstrike/tests/fixtures/bankofamerica.csv new file mode 100644 index 00000000..36dbe772 --- /dev/null +++ b/silverstrike/tests/fixtures/bankofamerica.csv @@ -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 \ No newline at end of file diff --git a/silverstrike/tests/test_importers.py b/silverstrike/tests/test_importers.py index 42de79c6..2c48a72e 100644 --- a/silverstrike/tests/test_importers.py +++ b/silverstrike/tests/test_importers.py @@ -22,6 +22,14 @@ 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)) @skipUnless(hasattr(importers, 'ofx'), 'ofxparse is not installed') def test_ofx(self): From b3db0a697c1265d5d933147a8704c26258a47aa8 Mon Sep 17 00:00:00 2001 From: Robin <> Date: Sun, 22 Dec 2019 12:28:03 -0600 Subject: [PATCH 2/2] add chase transaction importer --- silverstrike/importers/__init__.py | 6 +++-- silverstrike/importers/chase.py | 35 +++++++++++++++++++++++++++ silverstrike/tests/fixtures/chase.csv | 10 ++++++++ silverstrike/tests/test_importers.py | 8 ++++++ 4 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 silverstrike/importers/chase.py create mode 100644 silverstrike/tests/fixtures/chase.csv diff --git a/silverstrike/importers/__init__.py b/silverstrike/importers/__init__.py index e260c7fc..bdf4fed0 100644 --- a/silverstrike/importers/__init__.py +++ b/silverstrike/importers/__init__.py @@ -1,4 +1,4 @@ -from . import dkb, dkb_visa, pc_mastercard, volksbank, boa +from . import dkb, dkb_visa, pc_mastercard, volksbank, boa, chase IMPORTERS = [ dkb, @@ -6,6 +6,7 @@ pc_mastercard, volksbank, boa, + chase, ] IMPORTER_NAMES = [ @@ -13,7 +14,8 @@ 'DKB Visa', 'PC MasterCard', 'Volksbank', - 'Bank of America' + 'Bank of America', + 'Chase', ] try: diff --git a/silverstrike/importers/chase.py b/silverstrike/importers/chase.py new file mode 100644 index 00000000..4df9ec65 --- /dev/null +++ b/silverstrike/importers/chase.py @@ -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 \ No newline at end of file diff --git a/silverstrike/tests/fixtures/chase.csv b/silverstrike/tests/fixtures/chase.csv new file mode 100644 index 00000000..cbd8d1d9 --- /dev/null +++ b/silverstrike/tests/fixtures/chase.csv @@ -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 \ No newline at end of file diff --git a/silverstrike/tests/test_importers.py b/silverstrike/tests/test_importers.py index 2c48a72e..3f46a917 100644 --- a/silverstrike/tests/test_importers.py +++ b/silverstrike/tests/test_importers.py @@ -30,6 +30,14 @@ def test_bankofamerica(self): 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):