diff --git a/dch_webhooks.py b/dch_webhooks.py index 3b9037b..64488ce 100644 --- a/dch_webhooks.py +++ b/dch_webhooks.py @@ -146,9 +146,13 @@ class Firefly(HttpxClientMixin): rbody = r.json() attachment = rbody['data'] url = f'{FIREFLY_URL}/api/v1/attachments/{attachment["id"]}/upload' - r = await self.client.post(url, content=doc, headers={ - 'Content-Type': 'application/octet-stream', - }) + r = await self.client.post( + url, + content=doc, + headers={ + 'Content-Type': 'application/octet-stream', + }, + ) r.raise_for_status() @@ -249,13 +253,25 @@ class Paperless(HttpxClientMixin): MAX_DOCUMENT_SIZE, ) continue - docs.append( - (response_filename(r), doc.title, await r.aread()) - ) + docs.append((response_filename(r), doc.title, await r.aread())) return docs async def handle_firefly_transaction(xact: FireflyIIITransaction) -> None: + try: + xact0 = xact.transactions[0] + except IndexError: + log.warning('Received empty transaction Firefly?') + else: + message = ( + f'${xact0.amount} for {xact0.description} on {xact0.date.date()}' + ) + title = f'Firefly III: New {xact.transactions[0].type.title()}' + tags = 'money_with_wings' + try: + await ntfy(message, 'firefly', title, tags) + except Exception: + log.exception('Failed to send notification') async with Firefly() as ff, Paperless() as pl: for split in xact.transactions: search = clean_description(split.description)