File: firstdirect.py

package info (click to toggle)
ledger-autosync 1.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 508 kB
  • sloc: python: 2,711; makefile: 5
file content (25 lines) | stat: -rw-r--r-- 813 bytes parent folder | download | duplicates (2)
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
# ledger-autosync plugin for CSV files from First Direct, a UK bank.
# The currency is fixed to GBP for that reason.

import datetime
import re

from ledgerautosync.converter import Amount, CsvConverter, Posting, Transaction


class SomeConverter(CsvConverter):
    FIELDSET = set(["Date", "Description", "Amount"])

    def __init__(self, *args, **kwargs):
        super(SomeConverter, self).__init__(*args, **kwargs)

    def convert(self, row):
        amount = row["Amount"]
        return Transaction(
            date=datetime.datetime.strptime(row["Date"], "%d/%m/%Y"),
            payee=row["Description"].strip(),
            postings=[
                Posting(self.name, Amount(amount, "GBP")),
                Posting(self.unknownaccount, Amount(amount, "GBP", reverse=True)),
            ],
        )