Send ntfy messages for Firefly transactions
I want to get an alert whenever a new transaction is added to Firefly. This will be particularly helpful now that _xactmon_ is creating transactions automatically based on notifications from Commerce, Chase, etc.master
parent
60b61d64c6
commit
1681f3852d
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue