From a003cf9f8caf45a3792793d2a58ae6f8f71cfc15 Mon Sep 17 00:00:00 2001 From: Yves Fischer Date: Thu, 9 Nov 2017 23:41:34 +0100 Subject: improve transaction details formatting --- transfers.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'transfers.py') diff --git a/transfers.py b/transfers.py index c14055f..3580ce8 100755 --- a/transfers.py +++ b/transfers.py @@ -7,6 +7,7 @@ import logging from fints.client import FinTS3PinTanClient import peewee as p from slixmpp import ClientXMPP +import transaction_details logging.basicConfig(level=logging.INFO) @@ -28,6 +29,12 @@ class Transaction(p.Model): sepa_amount_str = p.CharField() sepa_transaction_details = p.CharField() + def format_message(self): + details = transaction_details.parse_transaction_details(self.sepa_transaction_details) + return "{accountnumber} {details[Buchungstext]}: {amount_str} {details[Verwendungszweck]}".format( + entry_date=self.sepa_entry_date, accountnumber=self.accountnumber, amount_str=self.sepa_amount_str, + details=details) + class Meta: database = db indexes = ((('accountnumber', 'sepa_entry_date', 'sepa_transaction_details'), True),) @@ -79,7 +86,7 @@ cl = ClientXMPP(config['jabber']['jid'], config['jabber']['password']) def session_start(event): cl.send_presence() for t in new_transactions: - message = "{} {} {}".format(t.accountnumber, t.sepa_amount_str, t.sepa_transaction_details) + message = t.format_message() cl.send_message(config['jabber']['recipient'], message, mtype='chat') logging.info("Sent info %s", message) cl.disconnect() -- cgit v1.2.1