@ -55,7 +55,11 @@ if not os.path.exists(tmp_dir):
os . makedirs ( tmp_dir )
# List of blocked events
blocked_events = config [ " Blocking " ] . get ( " BlockedEvents " ) . split ( " , " )
global_blocked_events = config [ " Blocking " ] . get ( " GlobalBlockedEvents " ) . split ( " , " )
sayalert_blocked_events = config [ " Blocking " ] . get ( " SayAlertBlockedEvents " ) . split ( " , " )
tailmessage_blocked_events = (
config [ " Blocking " ] . get ( " TailmessageBlockedEvents " ) . split ( " , " )
)
# Configuration for tailmessage
tailmessage_config = config [ " Tailmessage " ]
# Flag to enable/disable tailmessage
@ -252,7 +256,9 @@ logger.debug("Base directory: {}".format(baseDir))
logger . debug ( " Temporary directory: {} " . format ( tmp_dir ) )
logger . debug ( " Sounds path: {} " . format ( sounds_path ) )
logger . debug ( " Tailmessage path: {} " . format ( tailmessage_file ) )
logger . debug ( " Blocked events: {} " . format ( blocked_events ) )
logger . debug ( " Global Blocked events: {} " . format ( global_blocked_events ) )
logger . debug ( " SayAlert Blocked events: {} " . format ( sayalert_blocked_events ) )
logger . debug ( " Tailmessage Blocked events: {} " . format ( tailmessage_blocked_events ) )
def getAlerts ( countyCodes ) :
@ -292,10 +298,12 @@ def getAlerts(countyCodes):
expires_time = parser . isoparse ( expires )
if expires_time > current_time :
event = feature [ " properties " ] [ " event " ]
for blocked_event in blocked_events:
if fnmatch . fnmatch ( event , blocked_event) :
for global_ blocked_event in global_ blocked_events:
if fnmatch . fnmatch ( event , global_ blocked_event) :
logger . debug (
" Blocking {} as per configuration " . format ( event )
" Globally Blocking {} as per configuration " . format (
event
)
)
break
else :
@ -328,7 +336,14 @@ def sayAlert(alerts):
os . path . join ( sounds_path , " ALERTS " , " SWP95.wav " )
)
alert_count = 0 # Counter for alerts added to combined_sound
for alert in alerts :
# Check if alert is in the SayAlertBlockedEvents list
if alert in sayalert_blocked_events :
logger . debug ( " SayAlert blocking {} as per configuration " . format ( alert ) )
continue
try :
index = WS . index ( alert )
audio_file = AudioSegment . from_wav (
@ -336,6 +351,7 @@ def sayAlert(alerts):
)
combined_sound + = sound_effect + audio_file
logger . debug ( " Added {} (SWP {} .wav) to alert sound " . format ( alert , WA [ index ] ) )
alert_count + = 1 # Increment the counter
except ValueError :
logger . error ( " Alert not found: {} " . format ( alert ) )
except FileNotFoundError :
@ -345,6 +361,9 @@ def sayAlert(alerts):
)
)
if alert_count == 0 : # Check the counter instead of combined_sound.empty()
logger . debug ( " SayAlert: All alerts were blocked, not broadcasting any alerts. " )
else :
logger . debug ( " Exporting alert sound to {} " . format ( alert_file ) )
converted_combined_sound = convert_audio ( combined_sound )
converted_combined_sound . export ( alert_file , format = " wav " )
@ -401,6 +420,11 @@ def buildTailmessage(alerts):
os . path . join ( sounds_path , " ALERTS " , " SWP95.wav " )
)
for alert in alerts :
# Check if alert is in the TailmessageBlockedEvents list
if alert in tailmessage_blocked_events :
logger . debug ( " Alert blocked by TailmessageBlockedEvents: {} " . format ( alert ) )
continue
try :
index = WS . index ( alert )
audio_file = AudioSegment . from_wav (
@ -416,6 +440,11 @@ def buildTailmessage(alerts):
sounds_path , WA [ index ]
)
)
if combined_sound . empty ( ) :
logger . debug (
" BuildTailmessage: All alerts were blocked, creating silent tailmessage "
)
combined_sound = AudioSegment . silent ( duration = 100 )
logger . debug ( " Exporting tailmessage to {} " . format ( tailmessage_file ) )
converted_combined_sound = convert_audio ( combined_sound )
converted_combined_sound . export ( tailmessage_file , format = " wav " )