diff options
author | Yves Fischer <yvesf-git@xapek.org> | 2019-04-05 08:01:00 +0200 |
---|---|---|
committer | Yves Fischer <yvesf-git@xapek.org> | 2019-04-05 08:02:12 +0200 |
commit | cb9f2096cd6ae8bf8a894cc06600526448b584ca (patch) | |
tree | f3be927c49b0d6e1e56e8273e1d244559c22aab2 /transfers.py | |
parent | 7dc3d95458e9aeb2e3b71047af2f83786d075f9f (diff) | |
download | finanzstatus-cb9f2096cd6ae8bf8a894cc06600526448b584ca.tar.gz finanzstatus-cb9f2096cd6ae8bf8a894cc06600526448b584ca.zip |
Diffstat (limited to 'transfers.py')
-rwxr-xr-x | transfers.py | 55 |
1 files changed, 23 insertions, 32 deletions
diff --git a/transfers.py b/transfers.py index 3271832..63e051f 100755 --- a/transfers.py +++ b/transfers.py @@ -6,8 +6,8 @@ import logging from fints.client import FinTS3PinTanClient import peewee as p -from slixmpp import ClientXMPP -import transaction_details +from playhouse.fields import PickledField +from matrix_client.client import MatrixClient logging.basicConfig(level=logging.INFO) @@ -25,21 +25,20 @@ db = p.SqliteDatabase(args.db) class Transaction(p.Model): created_date = p.DateField(default=datetime.date.today) accountnumber = p.CharField() + identifier = p.CharField() sepa_entry_date = p.DateField() - sepa_amount = p.DecimalField() - sepa_transaction_details = p.CharField() - sepa_status = p.CharField() - sepa_currency = p.CharField() + details = PickledField() - def format_message(self): - details = transaction_details.parse_transaction_details(self.sepa_transaction_details) - return '{transaction[accountnumber]} {details[Buchungstext]}: {transaction[sepa_amount]} ' \ - '{transaction[sepa_currency]} {details[Auftraggeber Name]} {details[Verwendungszweck]}'.format( - transaction=self._data, details=details) + def format_message_html(self): + return """\ +{accountnumber} <b>{details[posting_text]}</b>: +<code>{details[amount].amount}</code> {details[amount].currency} +{details[applicant_name]} <i>{details[purpose]} {details[end_to_end_reference]}</i> +""".format(**self._data) class Meta: database = db - indexes = ((('accountnumber', 'sepa_entry_date', 'sepa_transaction_details'), True),) + indexes = ((('accountnumber', 'identifier'), True),) db.create_tables([Transaction], True) @@ -59,17 +58,14 @@ accounts = f.get_sepa_accounts() account = list(filter(lambda a: a.accountnumber == config['bank']['accountnumber'], accounts))[0] logging.info("select transactions on account %s starting from %s", account.accountnumber, last_transaction_date) -transactions = f.get_statement(account, last_transaction_date, datetime.date.today()) +transactions = f.get_transactions(account, last_transaction_date, datetime.date.today()) new_transactions = [] for t in transactions: - filter_pred = { - 'accountnumber': config['bank']['accountnumber'], - 'sepa_entry_date': datetime.date.fromordinal(t.data['entry_date'].toordinal()), - 'sepa_transaction_details': t.data['transaction_details'], - } - data = {'sepa_amount': t.data['amount'].amount, 'sepa_status': t.data['status'], - 'sepa_currency': t.data['currency']} + date = datetime.date.fromordinal(t.data['entry_date'].toordinal()), + identifier = "{applicant_bin}-{applicant_iban}-{mydate}".format(mydate=date, **t.data) + filter_pred = {'accountnumber': config['bank']['accountnumber'], 'identifier': identifier} + data = {'details': t.data, 'sepa_entry_date': date} try: record = Transaction.get(**filter_pred) record.update(data) @@ -82,18 +78,13 @@ for t in transactions: record.save() if len(new_transactions) > 0: - cl = ClientXMPP(config['jabber']['jid'], config['jabber']['password']) + client = MatrixClient(config['matrix']['host']) + token = client.login(config['matrix']['user'], config['matrix']['pass']) + room = client.join_room(config['matrix']['room']) - def session_start(event): - for t in new_transactions: - message = t.format_message() - cl.send_message(config['jabber']['recipient'], message, mtype='chat') - logging.info("Sent info %s", message) - cl.disconnect() + for t in new_transactions: + message = t.format_message_html() + room.send_html(message) - - cl.add_event_handler('session_start', session_start) - cl.add_event_handler('killed', lambda *_: cl.loop.stop()) - cl.connect() - cl.process() + client.logout() |