* Added docker folder to repo
* Ubuntu based docker file can be build from the repo's root by ``` docker-compose -f docker/docker-compose.yml build ``` * and started by ``` docker-compose -f docker/docker-compose.yml build ``` * Restructured code by packaging the CallMonitoring and SpeexConverting * main() runs on startup and then watches for disconnected calls as trigger for running again. * Commented main file
This commit is contained in:
36
libs/monitoring/__init__.py
Normal file
36
libs/monitoring/__init__.py
Normal file
@@ -0,0 +1,36 @@
|
||||
import queue
|
||||
from fritzconnection.core.fritzmonitor import FritzMonitor
|
||||
|
||||
### Monitor the calls of a fritzbox continously ###
|
||||
###################################################
|
||||
|
||||
def watch_disconnect(monitor, event_queue, func, healthcheck_interval=10):
|
||||
while True:
|
||||
try:
|
||||
event = event_queue.get(timeout=healthcheck_interval)
|
||||
except queue.Empty:
|
||||
# check health:
|
||||
if not monitor.is_alive:
|
||||
raise OSError("Error: fritzmonitor connection failed")
|
||||
else:
|
||||
# do event processing here:
|
||||
print(event)
|
||||
if 'DISCONNECT' in event:
|
||||
print("Anruf beendet. Jetzt den AB checken.\n")
|
||||
func()
|
||||
|
||||
|
||||
|
||||
def endedCall(func, fritz_ip='192.168.1.1'):
|
||||
"""
|
||||
Call this to trigger a given function if a call is disconnected
|
||||
"""
|
||||
try:
|
||||
# as a context manager FritzMonitor will shut down the monitor thread
|
||||
with FritzMonitor(address=fritz_ip) as monitor:
|
||||
event_queue = monitor.start()
|
||||
watch_disconnect(monitor, event_queue, func)
|
||||
except (OSError, KeyboardInterrupt) as err:
|
||||
print(err)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user