A live bird collage card for your Home Assistant dashboard.
Convert birdweather uploads to flac (#393)
Alexandre6572aa22b2fb
diff --git a/scripts/utils/reporting.py b/scripts/utils/reporting.pyindex 5763d393..336010b8 100644--- a/scripts/utils/reporting.py+++ b/scripts/utils/reporting.py@@ -6,6 +6,8 @@ import osimport sqlite3import subprocessimport tempfile+import io+import soundfilefrom time import sleepimport requests@@ -169,15 +171,22 @@ def bird_weather(file: ParseFileName, detections: [Detection]):if conf['BIRDWEATHER_ID'] == "":returnif detections:+ try:+ data, samplerate = soundfile.read(file.file_name)+ buf = io.BytesIO()+ soundfile.write(buf, data, samplerate, format='FLAC')+ flac_data = buf.getvalue()+ except Exception as e:+ log.error("Error during FLAC conversion: %s", e)+ return+ gzip_flac_data = gzip.compress(flac_data)+# POST soundscape to serversoundscape_url = (f'https://app.birdweather.com/api/v1/stations/'f'{conf["BIRDWEATHER_ID"]}/soundscapes?timestamp={file.iso8601}')- with open(file.file_name, 'rb') as f:- wav_data = f.read()- gzip_wav_data = gzip.compress(wav_data)try:- response = requests.post(url=soundscape_url, data=gzip_wav_data, timeout=30,+ response = requests.post(url=soundscape_url, data=gzip_flac_data, timeout=30,headers={'Content-Type': 'application/octet-stream', 'Content-Encoding': 'gzip'})log.info("Soundscape POST Response Status - %d", response.status_code)sdata = response.json()