diff --git a/README.md b/README.md index 4d25769..e2ecb92 100644 --- a/README.md +++ b/README.md @@ -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): diff --git a/medihunter.py b/medihunter.py index fcc9373..c892324 100644 --- a/medihunter.py +++ b/medihunter.py @@ -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() @@ -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": @@ -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') diff --git a/medihunter_notifiers.py b/medihunter_notifiers.py index 6f37f7b..c75030c 100644 --- a/medihunter_notifiers.py +++ b/medihunter_notifiers.py @@ -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: