From be1a6f13fd28ae3aaf1ad60fc7012040484e9d06 Mon Sep 17 00:00:00 2001 From: Alexandre <44178713+alexbelgium@users.noreply.github.com> Date: Tue, 9 Jul 2024 19:39:31 +0200 Subject: [PATCH] Update birdnet_to_mqtt.py --- birdnet-pi/rootfs/helpers/birdnet_to_mqtt.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/birdnet-pi/rootfs/helpers/birdnet_to_mqtt.py b/birdnet-pi/rootfs/helpers/birdnet_to_mqtt.py index 86d251af2..4f722cee1 100644 --- a/birdnet-pi/rootfs/helpers/birdnet_to_mqtt.py +++ b/birdnet-pi/rootfs/helpers/birdnet_to_mqtt.py @@ -23,7 +23,6 @@ logging.basicConfig(level=logging.INFO) # this generator function monitors the requested file handle for new lines added at its end # the newly added line is returned by the function def file_row_generator(s): - s.seek(0,2) while True : line = s.readline() if not line: @@ -49,10 +48,10 @@ re_all_found = re.compile(r'birdnet_analysis\.sh.*\(.*\)') re_found_bird = re.compile(r'\(([^)]+)\)') re_log_timestamp = re.compile(r'.+?(?= birdnet-)') -re_high_found = re.compile(r'(?<=python3\[).*\.mp3$') +re_high_found = re.compile(r'.*\.mp3$') re_high_clean = re.compile(r'(?<=\]:).*\.mp3$') -syslog = open('/config/BirdDB.txt', 'r') +syslog = open('/proc/1/fd/1', 'r') def on_connect(client, userdata, flags, rc, properties=None): """ Callback for when the client receives a CONNACK response from the server. """ @@ -89,9 +88,11 @@ mqttc.loop_start() # call the generator function and process each line that is returned for row in file_row_generator(syslog): # if line in log is from 'birdnet_analysis.sh' routine, then operate on it - + print(row) + # bird found above confidence level found, process it - if re_high_found.search(row) : + if re_high_found.search(row) : + print('yes') # this slacker regular expression work, extracts the data about the bird found from the log line # I do the parse in two passes, because I did not know the re to do it in one!