Skip to content

Commit

Permalink
Add File Check Prior to Pushing Images
Browse files Browse the repository at this point in the history
Add a file check to ensure the image file exists prior to sending a push
(in case the image was not created, avoiding messages being sent without
images).
  • Loading branch information
jekhokie committed Feb 18, 2021
1 parent 97ff833 commit a58937c
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 22 deletions.
48 changes: 33 additions & 15 deletions scripts/receive_meteor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,18 @@ if [ "$METEOR_RECEIVER" == "rtl_fm" ]; then
rm "${AUDIO_FILE_BASE}.bmp"
rm "${AUDIO_FILE_BASE}.dec"

if [ "$ENABLE_EMAIL_PUSH" == "true" ]; then
log "Emailing image" "INFO"
${PUSH_PROC_DIR}/push_email.sh "${EMAIL_PUSH_ADDRESS}" "${IMAGE_FILE_BASE}-122-rectified.jpg" "${annotation}" >> $NOAA_LOG 2>&1
fi

if [ "${ENABLE_DISCORD_PUSH}" == "true" ]; then
log "Pushing image to Discord" "INFO"
${PUSH_PROC_DIR}/push_discord.sh "${IMAGE_FILE_BASE}-122-rectified.jpg" "${annotation}" >> $NOAA_LOG 2>&1
if [ -f "${IMAGE_FILE_BASE}-122-rectified.jpg" ]; then
if [ "$ENABLE_EMAIL_PUSH" == "true" ]; then
log "Emailing image" "INFO"
${PUSH_PROC_DIR}/push_email.sh "${EMAIL_PUSH_ADDRESS}" "${IMAGE_FILE_BASE}-122-rectified.jpg" "${annotation}" >> $NOAA_LOG 2>&1
fi

if [ "${ENABLE_DISCORD_PUSH}" == "true" ]; then
log "Pushing image to Discord" "INFO"
${PUSH_PROC_DIR}/push_discord.sh "${IMAGE_FILE_BASE}-122-rectified.jpg" "${annotation}" >> $NOAA_LOG 2>&1
fi
else
log "No image produced - not pushing anywhere" "INFO"
fi

# insert or replace in case there was already an insert due to the spectrogram creation
Expand Down Expand Up @@ -220,18 +224,32 @@ elif [ "$METEOR_RECEIVER" == "gnuradio" ]; then
WHERE decoded_passes.id = $pass_id \
);"

# TODO: This is VERY not DRY - possibly put the image filenames in an array
# and iterate over it, which would significantly DRY this code up
if [ "$ENABLE_EMAIL_PUSH" == "true" ]; then
log "Emailing image" "INFO"
${PUSH_PROC_DIR}/push_email.sh "${EMAIL_PUSH_ADDRESS}" "${IMAGE_FILE_BASE}-122-rectified.jpg" "${annotation}" >> $NOAA_LOG 2>&1
${PUSH_PROC_DIR}/push_email.sh "${EMAIL_PUSH_ADDRESS}" "${IMAGE_FILE_BASE}-ir-122-rectified.jpg" "${annotation}" >> $NOAA_LOG 2>&1
${PUSH_PROC_DIR}/push_email.sh "${EMAIL_PUSH_ADDRESS}" "${IMAGE_FILE_BASE}-col-122-rectified.jpg" "${annotation}" >> $NOAA_LOG 2>&1
log "Emailing images" "INFO"
if [ -f "${IMAGE_FILE_BASE}-122-rectified.jpg" ]; then
${PUSH_PROC_DIR}/push_email.sh "${EMAIL_PUSH_ADDRESS}" "${IMAGE_FILE_BASE}-122-rectified.jpg" "${annotation}" >> $NOAA_LOG 2>&1
fi
if [ -f "${IMAGE_FILE_BASE}-ir-122-rectified.jpg" ]; then
${PUSH_PROC_DIR}/push_email.sh "${EMAIL_PUSH_ADDRESS}" "${IMAGE_FILE_BASE}-ir-122-rectified.jpg" "${annotation}" >> $NOAA_LOG 2>&1
fi
if [ -f "${IMAGE_FILE_BASE}-col-122-rectified.jpg" ]; then
${PUSH_PROC_DIR}/push_email.sh "${EMAIL_PUSH_ADDRESS}" "${IMAGE_FILE_BASE}-col-122-rectified.jpg" "${annotation}" >> $NOAA_LOG 2>&1
fi
fi

if [ "${ENABLE_DISCORD_PUSH}" == "true" ]; then
log "Pushing images to Discord" "INFO"
${PUSH_PROC_DIR}/push_discord.sh "${IMAGE_FILE_BASE}-122-rectified.jpg" "${annotation}" >> $NOAA_LOG 2>&1
${PUSH_PROC_DIR}/push_discord.sh "${IMAGE_FILE_BASE}-ir-122-rectified.jpg" "${annotation}" >> $NOAA_LOG 2>&1
${PUSH_PROC_DIR}/push_discord.sh "${IMAGE_FILE_BASE}-col-122-rectified.jpg" "${annotation}" >> $NOAA_LOG 2>&1
if [ -f "${IMAGE_FILE_BASE}-122-rectified.jpg" ]; then
${PUSH_PROC_DIR}/push_discord.sh "${IMAGE_FILE_BASE}-122-rectified.jpg" "${annotation}" >> $NOAA_LOG 2>&1
fi
if [ -f "${IMAGE_FILE_BASE}-ir-122-rectified.jpg" ]; then
${PUSH_PROC_DIR}/push_discord.sh "${IMAGE_FILE_BASE}-ir-122-rectified.jpg" "${annotation}" >> $NOAA_LOG 2>&1
fi
if [ -f "${IMAGE_FILE_BASE}-col-122-rectified.jpg" ]; then
${PUSH_PROC_DIR}/push_discord.sh "${IMAGE_FILE_BASE}-col-122-rectified.jpg" "${annotation}" >> $NOAA_LOG 2>&1
fi
fi

log "Cleaning up temp files" "INFO"
Expand Down
19 changes: 12 additions & 7 deletions scripts/receive_noaa.sh
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,18 @@ for enhancement in $ENHANCEMENTS; do
${IMAGE_PROC_DIR}/noaa_normalize_annotate.sh "${IMAGE_FILE_BASE}-$enhancement.jpg" "${annotation}" 90 >> $NOAA_LOG 2>&1
${IMAGE_PROC_DIR}/thumbnail.sh 300 "${IMAGE_FILE_BASE}-$enhancement.jpg" "${IMAGE_THUMB_BASE}-$enhancement.jpg" >> $NOAA_LOG 2>&1

if [ "${ENABLE_EMAIL_PUSH}" == "true" ]; then
log "Emailing image" "INFO"
${PUSH_PROC_DIR}/push_email.sh "${EMAIL_PUSH_ADDRESS}" "${IMAGE_FILE_BASE}-$enhancement.jpg" "${annotation}" >> $NOAA_LOG 2>&1
fi

if [ "${ENABLE_DISCORD_PUSH}" == "true" ]; then
${PUSH_PROC_DIR}/push_discord.sh "${IMAGE_FILE_BASE}-$enhancement.jpg" "${annotation}" >> $NOAA_LOG 2>&1
if [ -f "${IMAGE_FILE_BASE}-$enhancement.jpg" ]; then
if [ "${ENABLE_EMAIL_PUSH}" == "true" ]; then
log "Emailing image enhancement $enhancement" "INFO"
${PUSH_PROC_DIR}/push_email.sh "${EMAIL_PUSH_ADDRESS}" "${IMAGE_FILE_BASE}-$enhancement.jpg" "${annotation}" >> $NOAA_LOG 2>&1
fi

if [ "${ENABLE_DISCORD_PUSH}" == "true" ]; then
log "Pushing image enhancement $enhancement to Discord" "INFO"
${PUSH_PROC_DIR}/push_discord.sh "${IMAGE_FILE_BASE}-$enhancement.jpg" "${annotation}" >> $NOAA_LOG 2>&1
fi
else
log "No image with enhancement $enhancement created - not pushing anywhere" "INFO"
fi
fi
done
Expand Down

0 comments on commit a58937c

Please sign in to comment.