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

New plugin: Fidor Bank AG #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
43 changes: 20 additions & 23 deletions germany_fidorbank/README.rst
Original file line number Diff line number Diff line change
@@ -1,33 +1,29 @@
~~~~~~~~~~~~~~~~~~~~~~~
ofxstatement-1822direkt
ofxstatement-fidorbank UPDATE THIS README

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please remove/update this "UPDATE THIS README"

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's already been updated so this is safe to remove

~~~~~~~~~~~~~~~~~~~~~~~

`ofxstatement`_ plugin to support 1822direkt.com bank statements
`ofxstatement`_ plugin to support banking.fidor.de CSV bank statements

`ofxstatement`_ is a tool
to convert proprietary bank statement to OFX format, suitable for
importing into account programms like GnuCash or YNAB classic.
to convert proprietary bank statements to OFX format, suitable for
importing into account programs like GnuCash or YNAB.

Plugins for `ofxstatement`_ parses a particular
proprietary bank statement format and produces common data structure,
Plugins for `ofxstatement`_ parse a particular
proprietary bank statement format and produce common data structure,
that is then formatted into an OFX file.

This project provides an `ofxstatement`_ plugin for the German bank
1822direkt.com

1822direkt used to provide OFX downloads but have removed this
useful format and now only have a propriatay CSV (German version).
Shame on them.
Fidor Bank.

Using `ofxstatement`_ and this plugin, I successfully converted
CSV bank statements to OFX and import this into my accounting software.
I'm using YNAB classic for now. But GnuCash should also work fine.
CSV bank statements to OFX and imported this into YNAB. Any software
supporting the OFX format should work fine.


Requirements
============

You need python 3.x to run this as ofxstament seems to requires python3
You need python 3.x to run this as ofxstament requires python3


Installation
Expand All @@ -40,38 +36,40 @@ example:

pip3 install --user ofxstatement
git clone https://github.com/MirkoDziadzka/ofxstatement-germany
cd ofxstatement-germany/germany_1822direkt
cd ofxstatement-germany/germany_fidorbank
pip3 install --user .

Check the Python documentation on instructions for you operating system and
setup. Remember you must use Python 3.
Check the Python documentation on instructions for your operating system and
setup. Remember, you must use Python 3.


Setup
=====

Check if plugin is installed:
Check if the plugin is installed:

.. code:: bash

ofxstatement list-plugins

Expected output::

germany_1822direkt
germany_fidorbank

Edit config. The *account* is the ID used by your accounting program to
associate the transactions with a certain account. Probably you want to use
your bank account number (Kontonummer) i.e. the last 10 digits of your IBAN.
(Note: YNAB does not seem to care about this field, since you import directly
to the account screen anyway.)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At least in classic YNAB, you can import a file by starting YNAB with this file as an argument. This is what my import process is doing. It then uses the account data to find out into which of the YNAB accounts it should import this file.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm using this with the web version of YNAB, so less relevant. It might still do this from the All Accounts screen, but I haven't tried.


.. code:: bash

ofxstatement edit-config

A text editor will open. Configure something like this::

[1822direkt]
plugin = germany_1822direkt
[fidorbank]
plugin = germany_fidorbank
account = 0123456789

Some other config options you may set are:
Expand All @@ -85,8 +83,7 @@ Usage
=====

.. code:: bash

ofxstatement convert -t 1822direkt umsaetze-0123456789-03.02.2018_15_05.csv test.ofx
ofxstatement convert -t fidorbank umsaetze-0123456789-03.02.2018_15_05.csv test.ofx

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this is default filename for CSV files downloaded from Fidor? I would like to keep the names of the files realistic.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it's e.g. 2018-05-26-164912-Fidorpay-Transaktionen.csv


You may then import *test.ofx* into any accounting program which
accepts OFX, for example YNAB-classix or gnuCash.
Expand Down
12 changes: 6 additions & 6 deletions germany_fidorbank/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
from setuptools import find_packages
from distutils.core import setup

version = "0.0.2"
version = "0.0.1"

with open('../README.rst') as f:
long_description = f.read()

setup(name='ofxstatement-germany-1822direkt',
setup(name='ofxstatement-germany-fidorbank',
version=version,
author="Mirko Dziadzka",
author_email="mirko.dziadzka@gmail.com",
author="Kevin Kaland",
author_email="kevin@wizonesolutions.com",
url="https://github.com/MirkoDziadzka/ofxstatement_germany",
description=("ofxstatement plugin for Frankfurter Sparkasse / 1822direkt.com"),
description=("ofxstatement plugin for Fidor Bank AG / banking.fidor.de"),
long_description=long_description,
license="GPLv3",
keywords=["ofx", "banking", "statement"],
Expand All @@ -33,7 +33,7 @@
entry_points={
'ofxstatement':
[
'germany_1822direkt = ofxstatement.plugins.germany_1822direkt:FrankfurterSparkasse1822Plugin',
'germany_fidorbank = ofxstatement.plugins.germany_fidorbank:FidorBankAGPlugin',
]
},
install_requires=['ofxstatement'],
Expand Down
62 changes: 0 additions & 62 deletions germany_fidorbank/src/ofxstatement/plugins/germany_1822direkt.py

This file was deleted.

74 changes: 74 additions & 0 deletions germany_fidorbank/src/ofxstatement/plugins/germany_fidorbank.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import csv
import hashlib
import re

from ofxstatement.plugin import Plugin
from ofxstatement.parser import CsvStatementParser
from ofxstatement.statement import StatementLine


class FidorBankAGPlugin(Plugin):
def get_parser(self, filename):
encoding = self.settings.get('charset', 'utf-8')
with open(filename, 'r', encoding=encoding) as f:
lines = f.readlines()
parser = FidorBankAGParser(lines)
parser.statement.account_id = self.settings['account']
parser.statement.bank_id = self.settings.get('bank', '50050201')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This default 50050201 does not make sense with Fidor Bank, it's the BLZ from 1822direkt

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For Fidor, looks like it is 70022200

parser.statement.currency = self.settings.get('currency', 'EUR')
return parser


class FidorBankAGParser(CsvStatementParser):
"""
This plugin tries to parse the provided CSV data into OFX format.
"""
date_format = "%d.%m.%Y"

def split_records(self):
return csv.reader(self.fin, delimiter=';')

def parse_float(self, f):
""" convert a number in german localization (e.g. 1.234,56) to float """
return float(f.replace('.', '').replace(',', '.'))

def parse_record(self, line):
if self.cur_record < 2:
return None
sl = StatementLine()
# Build an ID based on an MD5 of the whole line.
original_line = ";".join(line)
hl = hashlib.new('md5');
hl.update(original_line.encode('utf-8'))
sl.id = hl.hexdigest()
sl.date = self.parse_datetime(line[0])
sl.amount = self.parse_float(line[3])
sl.trntype = 'DEBIT' if sl.amount < 0 else 'CREDIT'
# Payees generally follow a few formats.
# Variations in Beschreibung:
# MasterCard Onlinekauf bei <PAYEE>
# MasterCard Gutschrift in Höhe von <AMOUNT> bei <PAYEE>
# Variations in Beschreibung2:
# Empfänger: <PAYEE>, IBAN: <IBAN>, BIC: <BIC>
# Absender: <PAYEE>, IBAN: <IBAN>, BIC: <BIC>
# Beschreibung2 is empty when the payee is in Beschreibung.
# Default to blank for unknown patterns.
sl.payee = ''

beschreibung2 = "" + line[2]
if (beschreibung2).strip() != '':
# Split the Beschreibung2 value by comma, then each list element by comma. Use the second value of the
# first element for the Payee.
desc_parts = beschreibung2.split(",")
desc1_parts = ("" + desc_parts[0]).split(":")
sl.payee = ("" + desc1_parts[1]).strip()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why adding the empty string here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not that experienced in Python, and I wanted PyCharm's code hints to work properly. So type coercion, basically.

else:
pattern = re.compile('.+ bei (.+)$')
match = pattern.match(line[1])
if match:
sl.payee = match.group(1)

# Use Beschreibung as the memo.
sl.memo = line[1]

return sl