Support desktop notifications on Linux with notify-send

This commit is contained in:
grym 2022-01-21 22:51:07 -05:00
parent 0db70aaba1
commit 67c2ea285b
2 changed files with 26 additions and 1 deletions

View File

@ -1 +1,2 @@
__version__ = "0.1.0"
appname = __name__

View File

@ -1,6 +1,7 @@
import csv
import functools
import itertools
import subprocess
import time
from datetime import datetime
from enum import Enum
@ -14,6 +15,8 @@ from pydantic import BaseModel, BaseSettings, Field
from tabulate import tabulate as tab
from tabulate import tabulate_formats
from fedmon import appname
app = typer.Typer()
tabulate_formats = set(tabulate_formats)
@ -99,7 +102,15 @@ def format_response(summary: Summary, format: AllowedFormat, count: int) -> str:
@app.command()
def main(format: AllowedFormat = typer.Option(default="json", show_choices=True)):
def main(
format: AllowedFormat = typer.Option(
default="json", show_choices=True, help="The format to display results in."
),
send_notification: bool = typer.Option(
default=False,
help="If set, use `notify-send` to raise a desktop notification, if available.",
),
):
prev = None
counter = itertools.count()
while True:
@ -109,5 +120,18 @@ def main(format: AllowedFormat = typer.Option(default="json", show_choices=True)
if summary != prev:
if summary:
typer.echo(format_response(summary, format, next(counter)))
if send_notification:
try:
subprocess.check_call(
[
"notify-send",
appname,
format_response(
summary, AllowedFormat.json, next(counter)
),
]
)
except subprocess.CalledProcessError as e:
typer.echo(e, err=True)
prev = summary
time.sleep(config.poll)