Skip to content

Commit

Permalink
Merge pull request #44 from rafal-krypa/pushbullet
Browse files Browse the repository at this point in the history
Add Pushbullet notifier
  • Loading branch information
apqlzm authored Feb 6, 2023
2 parents a30d972 + e670e64 commit cbd928e
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,28 @@ opcja|domyślna wartość
--pushover_msgtitle|brak - prefix dodawany przed tytułem powiadomienia
-t, --notification-title|brak, dostępna tylko w medihunter.py, wspierana tylko przez Pushover i Telegram

## Pushbullet w medihunter.py

Żeby działały powiadomienia pushbullet trzeba zrobić eksport (wartości ustawiamy swoje):

```shell
# bash
export NOTIFIERS_PUSHBULLET_TOKEN=avykwnqc8ohyk73mo1bsuggsm3r4qf
```

lub

```shell
# fish
set -x NOTIFIERS_PUSHBULLET_TOKEN avykwnqc8ohyk73mo1bsuggsm3r4qf
```

Teraz możemy wyszukać wizyty np. tak:

```shell
medihunter find-appointment -n pushbullet -r 204 -s 4798 --user 00000 --password psw1234 -i 1 -d 2019-05-15
```

## Pushover w medihunter.py

Żeby działały powiadomienia pushover trzeba zrobić eksport (wartości ustawiamy swoje):
Expand Down
6 changes: 4 additions & 2 deletions medihunter.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
Appointment,
MedicoverSession,
)
from medihunter_notifiers import pushover_notify, telegram_notify, xmpp_notify
from medihunter_notifiers import pushbullet_notify, pushover_notify, telegram_notify, xmpp_notify

load_dotenv()
now = datetime.now()
Expand Down Expand Up @@ -46,6 +46,8 @@ def duplicate_checker(appointment: Appointment) -> bool:
def notify_external_device(message: str, notifier: str, **kwargs):
# TODO: add more notification providers
title = kwargs.get("notification_title")
if notifier == "pushbullet":
pushbullet_notify(message, title)
if notifier == "pushover":
pushover_notify(message, title)
elif notifier == "telegram":
Expand Down Expand Up @@ -116,7 +118,7 @@ def validate_arguments(**kwargs) -> bool:
@click.option("--service", "-e", default=-1)
@click.option("--interval", "-i", default=0, show_default=True, help='Checking interval in minutes')
@click.option("--days-ahead", "-j", default=1, show_default=True)
@click.option("--enable-notifier", "-n", type=click.Choice(["pushover", "telegram", "xmpp"]))
@click.option("--enable-notifier", "-n", type=click.Choice(["pushbullet", "pushover", "telegram", "xmpp"]))
@click.option("--notification-title", "-t")
@click.option("--user", prompt=True, envvar='MEDICOVER_USER')
@click.password_option(confirmation_prompt=False, envvar='MEDICOVER_PASS')
Expand Down
14 changes: 14 additions & 0 deletions medihunter_notifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,23 @@
from os import environ
from xmpp import *

pushbullet = get_notifier('pushbullet')
pushover = get_notifier('pushover')
telegram = get_notifier('telegram')

def pushbullet_notify(message, title: str = None):
try:
if title is None:
r = pushbullet.notify(message=message)
else:
r = pushbullet.notify(message=message, title=title)
except BadArguments as e:
print(f'Pushbullet failed\n{e}')
return

if r.status != 'Success':
print(f'Pushbullet notification failed:\n{r.errors}')

def pushover_notify(message, title: str = None):
try:
if title is None:
Expand Down

0 comments on commit cbd928e

Please sign in to comment.