forked from Nachtzuster/BirdNET-Pi
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmost_recent.sh
More file actions
executable file
·31 lines (28 loc) · 892 Bytes
/
most_recent.sh
File metadata and controls
executable file
·31 lines (28 loc) · 892 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/env bash
OLDIFS=$IFS
IFS=\|
most_recent_results=($(sqlite3 ~/BirdNET-Pi/scripts/birds.db \
'SELECT Com_Name, Time, Date FROM detections
ORDER BY Date DESC, Time DESC
LIMIT 1'))
today=$(date +%F)
yesterday=$(date --date="yesterday" +%F)
two_days_ago=$(date --date="2 days ago" +%F)
echo -n The most recent detection was
if [[ "${most_recent_results[0]}" =~ ^[AEIOU].* ]];then
echo -n " an ${most_recent_results[0]} at "
else
echo -n " a ${most_recent_results[0]} at "
fi
most_recent_results[1]=$(date --date="${most_recent_results[1]}" +%l:%M%p)
echo -n ${most_recent_results[1]}
if [[ ${most_recent_results[2]} == $today ]];then
echo " today."
elif [[ ${most_recent_results[2]} == $yesterday ]];then
echo " yesterday."
elif [[ ${most_recent_results[2]} == $two_days_ago ]];then
echo " two days ago."
else
echo " on ${most_recent_results[2]}."
fi
IFS=$OLDIFS