From 61f9d082d8ac5bfb5e7123103a7a4c7d2b7790ca Mon Sep 17 00:00:00 2001 From: Alexandre <44178713+alexbelgium@users.noreply.github.com> Date: Wed, 10 Jul 2024 13:33:24 +0200 Subject: [PATCH] Confirmed working --- birdnet-pi/rootfs/helpers/birdnet_to_mqtt.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/birdnet-pi/rootfs/helpers/birdnet_to_mqtt.py b/birdnet-pi/rootfs/helpers/birdnet_to_mqtt.py index 076a64aae..a87b62d45 100644 --- a/birdnet-pi/rootfs/helpers/birdnet_to_mqtt.py +++ b/birdnet-pi/rootfs/helpers/birdnet_to_mqtt.py @@ -62,11 +62,8 @@ def get_bird_code(scientific_name): array_str = re.search(r'\$ebirds = \[(.*?)\];', data, re.DOTALL).group(1) # Convert the PHP array to a Python dictionary - bird_dict = {} - for line in array_str.split('\n'): - if '=>' in line: - key, value = map(lambda x: x.strip(' "'), line.split('=>')) - bird_dict[key] = value + bird_dict = {re.search(r'"(.*?)"', line).group(1): re.search(r'=> "(.*?)"', line).group(1) + for line in array_str.split('\n') if '=>' in line} # Return the corresponding value for the given bird's scientific name return bird_dict.get(scientific_name)