Skip to content

Commit

Permalink
Merge pull request #2 from femke-sintef/main
Browse files Browse the repository at this point in the history
Improvement: message to log contains more information
  • Loading branch information
BenCretois authored Apr 8, 2024
2 parents 785c0c6 + 727205e commit 4e289ff
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions cloud_analysis/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ def send_email(subject, body):
server.send_message(msg)
server.quit()
logging.info("Email sent successfully!")
return "Succes"
except Exception as e:
logging.error(f"Error sending email: {e}")
return repr(e)


from pydub import AudioSegment
Expand Down Expand Up @@ -243,6 +245,7 @@ def process_audio_endpoint():
results, maxes = on_process_audio(audio_id, audio_rec, bucket_name, blob_name, hr, conf)
max_conf, max_hr = maxes

email_response = "Not sent"
if results > 1:
# Create a signed URL
download_url = generate_signed_url(bucket_name, blob_name)
Expand All @@ -254,9 +257,9 @@ def process_audio_endpoint():
email_body = f"{results} snowmobile detections were made in the audio file!\n"
email_body += f"Detections come from: {location}\n"
email_body += f"Download the audio file here: {download_url}"
send_email("Snowmobile Detection Alert", email_body)
email_response = send_email("Snowmobile Detection Alert", email_body)

return jsonify({"message": f"file {blob_name} processed. Max CONF = {max_conf}, MAX HR = {max_hr}"})
return jsonify({"message": f"file {blob_name} processed. Max CONF = {max_conf}, MAX HR = {max_hr}, DET COUNT = {results}, E-MAIL = {email_response}"})


if __name__ == "__main__":
Expand Down

0 comments on commit 4e289ff

Please sign in to comment.