add apprise and send notification when refreshing listings
This commit is contained in:
parent
ce386e748d
commit
762408e054
6 changed files with 105 additions and 6 deletions
27
crawler/notifications.py
Normal file
27
crawler/notifications.py
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
from abc import abstractmethod
|
||||
from enum import StrEnum
|
||||
import apprise
|
||||
from functools import lru_cache
|
||||
|
||||
|
||||
class Surface:
|
||||
@abstractmethod
|
||||
def connection_string(self) -> str | None:
|
||||
...
|
||||
|
||||
class Slack(Surface):
|
||||
def connection_string(self) -> str | None:
|
||||
return "https://hooks.slack.com/services/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"
|
||||
|
||||
|
||||
@lru_cache(maxsize=None)
|
||||
def get_notifier(surfaces: list[Surface] | None = None) -> apprise.Apprise:
|
||||
surfaces = surfaces or [Slack()]
|
||||
obj = apprise.Apprise()
|
||||
for surface in surfaces:
|
||||
obj.add(surface.connection_string())
|
||||
return obj
|
||||
|
||||
async def send_notification( body: str, title: str='') -> bool:
|
||||
notifier = get_notifier()
|
||||
return await notifier.async_notify(body=body, title=title)
|
||||
Loading…
Add table
Add a link
Reference in a new issue