Skip to content

Commit

Permalink
Destinations (#290)
Browse files Browse the repository at this point in the history
* Race fix

* Handle missing destination address (just keep going!)
  • Loading branch information
jquagga authored Nov 14, 2024
1 parent 85de801 commit aade1e3
Showing 1 changed file with 25 additions and 15 deletions.
40 changes: 25 additions & 15 deletions ttt.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
# impact system functionality overall.
os.nice(5)

# Are we using Deepgram, Whisper, or transformers?
# We only need torch if using transformers so let's not
# waste GPU ram if we're using another service
if os.environ.get("TTT_DEEPGRAM_KEY", False):
whisper_variant = "deepgram"
elif os.environ.get("TTT_WHISPERCPP_URL", False):
Expand Down Expand Up @@ -78,6 +81,7 @@ def transcribe_transformers(calljson, audiofile):


def send_notifications(calljson, audiofile, destinations):
# sourcery skip: do-not-use-bare-except
"""
Sends notifications based on call information.
Expand All @@ -99,22 +103,28 @@ def send_notifications(calljson, audiofile, destinations):
)
short_name = str(calljson["short_name"])
talkgroup = str(calljson["talkgroup"])
notify_url = destinations[short_name][talkgroup]
try:
notify_url = destinations[short_name][talkgroup]

# If TTT_ATTACH_AUDIO is set to True, attach it to apprise notification
attach_audio = os.environ.get("TTT_ATTACH_AUDIO", "False").lower() in (
"true",
"1",
"t",
)
apobj = apprise.Apprise()
apobj.add(notify_url)
if attach_audio:
audio_notification(audiofile, apobj, body, title)
else:
apobj.notify(
body=body,
title=title,
# If TTT_ATTACH_AUDIO is set to True, attach it to apprise notification
attach_audio = os.environ.get("TTT_ATTACH_AUDIO", "False").lower() in (
"true",
"1",
"t",
)
apobj = apprise.Apprise()
apobj.add(notify_url)
if attach_audio:
audio_notification(audiofile, apobj, body, title)
else:
apobj.notify(
body=body,
title=title,
)
# trunk-ignore(ruff/E722)
except:
print(
"Notification generation failed. This is usually a missing destination in destination.csv"
)


Expand Down

0 comments on commit aade1e3

Please sign in to comment.