summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAviad Rom <aviad.t.rom@gmail.com>2021-05-18 18:57:43 +0300
committerGitHub <noreply@github.com>2021-05-18 18:57:43 +0300
commit34057071555ac032103d0dde0d3241d0b9c244dd (patch)
tree1174686dfac4775edef3aef1262adbe7218e6978
parent4f2e6281b31af15c9cff15ca299d6512bd88fd21 (diff)
Add Mac OS push notifications (#11) and bump to v1.2.0v1.2.0
* push notifications on mac os * update readme * use self.output_error on missing notifications executable Co-authored-by: Aviad Rom <aviad@zebra-med.com>
-rw-r--r--README.md2
-rw-r--r--alarmpy/alarmpy.py16
-rw-r--r--setup.py2
3 files changed, 19 insertions, 1 deletions
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",