forked from kedder/ofxstatement-sample
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
TheoMarescaux
committed
Feb 11, 2016
1 parent
d1c12a9
commit c336958
Showing
4 changed files
with
82 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,12 +9,12 @@ | |
with open('README.rst') as f: | ||
long_description = f.read() | ||
|
||
setup(name='ofxstatement-sample', | ||
setup(name='ofxstatement-be-ing', | ||
version=version, | ||
author="Andrey Lebedev", | ||
author_email="[email protected]", | ||
url="https://github.com/kedder/ofxstatement", | ||
description=("Sample plugin for ofxstatement"), | ||
author="Theodore Marescaux", | ||
author_email="[email protected]", | ||
url="https://github.com/TheoMarescaux/ofxstatement-be-ing", | ||
description=("OFXStatement plugin for ING (Belgium)"), | ||
long_description=long_description, | ||
license="GPLv3", | ||
keywords=["ofx", "banking", "statement"], | ||
|
@@ -32,7 +32,7 @@ | |
namespace_packages=["ofxstatement", "ofxstatement.plugins"], | ||
entry_points={ | ||
'ofxstatement': | ||
['sample = ofxstatement.plugins.sample:SamplePlugin'] | ||
['ingbe = ofxstatement.plugins.ingbe:IngBePlugin'] | ||
}, | ||
install_requires=['ofxstatement'], | ||
include_package_data=True, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import csv | ||
|
||
from ofxstatement import statement | ||
from ofxstatement.plugin import Plugin | ||
from ofxstatement.parser import CsvStatementParser | ||
from ofxstatement.parser import StatementParser | ||
from ofxstatement.statement import StatementLine | ||
|
||
class IngBePlugin(Plugin): | ||
"""ING Belgium Plugin | ||
""" | ||
|
||
def get_parser(self, filename): | ||
f = open(filename, 'r', encoding=self.settings.get("charset", "ISO-8859-1")) | ||
parser = IngBeParser(f) | ||
#parser.statement.bank_id = "ING Belgium" | ||
#parser.statement.bank_id = self.settings.get('bank', 'ING Belgium') | ||
return parser | ||
|
||
class IngBeParser(CsvStatementParser): | ||
|
||
date_format = "%d/%m/%Y" | ||
mappings = { | ||
'check_no': 3, | ||
'date': 4, | ||
'payee': 2, | ||
'memo': 9, | ||
'amount': 6 | ||
} | ||
|
||
def parse(self): | ||
"""Main entry point for parsers | ||
super() implementation will call to split_records and parse_record to | ||
process the file. | ||
""" | ||
stmt = super(IngBeParser, self).parse() | ||
statement.recalculate_balance(stmt) | ||
return stmt | ||
|
||
def split_records(self): | ||
"""Return iterable object consisting of a line per transaction | ||
""" | ||
|
||
reader = csv.reader(self.fin) | ||
next(reader, None) | ||
return reader | ||
|
||
def parse_record(self, line): | ||
"""Parse given transaction line and return StatementLine object | ||
""" | ||
|
||
# Remove non CSV cr*p and zero-value notifications | ||
if(line[5] and not (line[6]=="0" and line[7]=="0")): | ||
transaction_id = line[3] | ||
date = line[4] | ||
date_value = line[5] | ||
account_to = line[2] | ||
currency = line[8] | ||
|
||
# fix amount - Well done ING, mixing the comma as decimal separator and as CSV delimiter. Way to go... | ||
line[6] = line[6]+"."+line[7] | ||
amount = line[6] | ||
|
||
# Pack info in description | ||
line[9] = line[9]+"-"+line[10]+"-"+line[11] | ||
description = line[9] | ||
|
||
stmtline = super(IngBeParser, self).parse_record(line) | ||
stmtline.trntype = 'DEBIT' if stmtline.amount < 0 else 'CREDIT' | ||
|
||
return stmtline |
This file was deleted.
Oops, something went wrong.