From df1594808370bb3644b7aa8510c861daa77f6d60 Mon Sep 17 00:00:00 2001 From: frederik Date: Sat, 2 Aug 2025 19:32:43 +0200 Subject: [PATCH] flake8 fixes --- scripts/server.py | 6 +----- scripts/species.py | 6 ++---- scripts/utils/notifications.py | 7 +++++-- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/scripts/server.py b/scripts/server.py index e54ddae..ef16f34 100644 --- a/scripts/server.py +++ b/scripts/server.py @@ -94,9 +94,6 @@ def loadMetaModel(): def predictFilter(lat, lon, week): - - global M_INTERPRETER - # Does interpreter exist? if M_INTERPRETER is None: loadMetaModel() @@ -209,7 +206,6 @@ def custom_sigmoid(x, sensitivity=1.0): def predict(sample, sensitivity): - global INTERPRETER # Make a prediction INTERPRETER.set_tensor(INPUT_LAYER_INDEX, np.array(sample[0], dtype='float32')) if model == "BirdNET_6K_GLOBAL_MODEL": @@ -240,7 +236,7 @@ def predict(sample, sensitivity): def analyzeAudioData(chunks, lat, lon, week, sens, overlap,): - global INTERPRETER, WEEK + global WEEK sensitivity = max(0.5, min(1.0 - (sens - 1.0), 1.5)) diff --git a/scripts/species.py b/scripts/species.py index 84c85b1..56be8be 100644 --- a/scripts/species.py +++ b/scripts/species.py @@ -11,9 +11,10 @@ try: except BaseException: from tensorflow import lite as tflite +M_INTERPRETER, M_INPUT_LAYER_INDEX, M_OUTPUT_LAYER_INDEX, CLASSES = (None, None, None, None) + def loadMetaModel(): - global M_INTERPRETER global M_INPUT_LAYER_INDEX global M_OUTPUT_LAYER_INDEX @@ -42,9 +43,6 @@ def loadMetaModel(): def predictFilter(lat, lon, week): - - global M_INTERPRETER - # Does interpreter exist? try: if M_INTERPRETER is None: diff --git a/scripts/utils/notifications.py b/scripts/utils/notifications.py index e5868d8..e0c79b7 100644 --- a/scripts/utils/notifications.py +++ b/scripts/utils/notifications.py @@ -14,6 +14,7 @@ DB_PATH = userDir + '/BirdNET-Pi/scripts/birds.db' flickr_images = {} species_last_notified = {} + asset = apprise.AppriseAsset( plugin_paths=[ userDir + "/.apprise/plugins", @@ -107,13 +108,15 @@ def sendAppriseNotifications(species, confidence, confidencepct, path, # TODO: Make this work with non-english comnames. Implement the "// convert sci name to English name" logic from overview.php here headers = {'User-Agent': 'Python_Flickr/1.0'} url = ('https://www.flickr.com/services/rest/?method=flickr.photos.search&api_key=' + str(settings_dict.get('FLICKR_API_KEY')) + - '&text=' + str(comName) + ' bird&sort=relevance&per_page=5&media=photos&format=json&license=2%2C3%2C4%2C5%2C6%2C9&nojsoncallback=1') + '&text=' + str(comName) + + ' bird&sort=relevance&per_page=5&media=photos&format=json&license=2%2C3%2C4%2C5%2C6%2C9&nojsoncallback=1') resp = requests.get(url=url, headers=headers, timeout=10) resp.encoding = "utf-8" data = resp.json()["photos"]["photo"][0] - image_url = 'https://farm'+str(data["farm"])+'.static.flickr.com/'+str(data["server"])+'/'+str(data["id"])+'_'+str(data["secret"])+'_n.jpg' + image_url = ('https://farm' + str(data["farm"]) + '.static.flickr.com/' + str(data["server"]) + '/' + + str(data["id"]) + '_'+str(data["secret"]) + '_n.jpg') flickr_images[comName] = image_url except Exception as e: print("FLICKR API ERROR: "+str(e))