From 34057071555ac032103d0dde0d3241d0b9c244dd Mon Sep 17 00:00:00 2001 From: Aviad Rom Date: Tue, 18 May 2021 18:57:43 +0300 Subject: Add Mac OS push notifications (#11) and bump to v1.2.0 * push notifications on mac os * update readme * use self.output_error on missing notifications executable Co-authored-by: Aviad Rom --- README.md | 2 ++ alarmpy/alarmpy.py | 16 ++++++++++++++++ setup.py | 2 +- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 13b1d76..979ef1d 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,8 @@ Options: --alarm-id Print alarm IDs --repeat-alarms Do not suppress ongoing alarms --quiet Print only active alarms + --desktop-notifications Create push notifications on your desktop + notification center (currently only in Mac OS) --help Show this message and exit. ``` diff --git a/alarmpy/alarmpy.py b/alarmpy/alarmpy.py index 1ee56ab..2a752d5 100644 --- a/alarmpy/alarmpy.py +++ b/alarmpy/alarmpy.py @@ -1,5 +1,6 @@ import click import json +import os import requests from collections import defaultdict @@ -26,6 +27,7 @@ class Alarm: alarm_id=False, repeat_alarms=False, quiet=False, + desktop_notifications=False ): self.language = language self.polling_delay = polling_delay @@ -34,6 +36,11 @@ class Alarm: self.repeat_alarms = repeat_alarms self.quiet = quiet + if desktop_notifications and not os.path.exists("/usr/bin/osascript"): + self.output_error("Desktop notifications are currently only available for MacOS") + desktop_notifications = False + self.desktop_notifications = desktop_notifications + self.current_alarms = [] self.last_routine_output = 0 @@ -126,6 +133,10 @@ class Alarm: cities_str = ", ".join(cities) click.secho(f"\t{area:<20} ", fg="red", bold=True, nl=False) click.secho(f"\t{cities_str} ", fg="red") + if self.desktop_notifications: + os.system( + f"/usr/bin/osascript -e 'display notification \"{cities_str}\" with title \"Alarms at {area}\"'" + ) if self.alarm_id: click.secho(f"({alarm_id})") @@ -160,6 +171,11 @@ class Alarm: @click.option("--alarm-id", is_flag=True, help="Print alarm IDs") @click.option("--repeat-alarms", is_flag=True, help="Do not suppress ongoing alarms") @click.option("--quiet", is_flag=True, help="Print only active alarms") +@click.option( + "--desktop-notifications", + is_flag=True, + help="Create push notifications on your desktop notification center (currently only in Mac OS)", +) def cli(**kwargs): Alarm(**kwargs).start() diff --git a/setup.py b/setup.py index 0eb10e7..e8952c0 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ with open("README.md", "r", encoding="utf-8") as fh: setuptools.setup( name="alarmpy", - version="1.1.0", + version="1.2.0", author="Yuval Adam", author_email="_@yuv.al", description="Pikud Ha'oref Alarm Tracking", -- cgit v1.3.1