-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart-automation-if-no-show.sh
executable file
·65 lines (58 loc) · 2.23 KB
/
start-automation-if-no-show.sh
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/bash
function get_show_date () {
file=$1
seconds=$2
date_string=`echo "$file" | cut -f1 -d'-' | sed "s/_/ /g"`
# split on the '-' character and replace _ with ' ' so date works properly
if [ -z ${2+x} ] ; then
date --date="$date_string"
else
# option to get date as seconds format
date --date="$date_string" +%s
fi
}
function get_next_show() {
# bash arrays are really horrifying this took forever to get right
shows=("$@")
# We subtract a minute just in case there is overlap in shows
current_date=`date +%s -d '1 minute ago'`
# I created a fake show in 2030 as the maximum
next_show="20300101_0000-not-actual-show"
# wow that syntax is ugly, but it looks through the show names
for show in "${shows[@]}"
do
next_show_date=`get_show_date $next_show seconds`
show_date=`get_show_date $show seconds`
# we want the minimum show time that is greater than the current date
if [[ "$show_date" > "$current_date" ]] && [[ "$show_date" < "$next_show_date" ]]
then
next_show="$show"
fi
done
if [ "$next_show" = "20300101_0000-not-actual-show" ] ; then
# this means we didn't find a next show
echo ""
else
echo "$next_show"
fi
}
# Grab all the shows in the directory
IFS=$'\n'
export MYSQL_PWD=`bash ./credentials.sh`
shows=(`mysql Rivendell -sN -u rduser -h 192.168.9.240 -e "select TITLE from CART where GROUP_NAME = 'Shows';"`)
echo $shows
# Lord have mercy is that array syntax ugly...
next_show=`get_next_show "${shows[@]}"`
if [ -z $next_show ] ; then
rmlsend EX\ 999998\!
exit 0
fi
next_show_date=`get_show_date $next_show`
echo -e "The next show is:\n$next_show\nwhich will begin playing at:\n$next_show_date"
next_show_date_seconds=`get_show_date $next_show seconds`
# date doesn't understand "from now" but does understand "hence" ... no comment
date_plus_minute=`date -d '1 minute hence' +%s`
if [[ "$next_show_date_seconds" > "$date_plus_minute" ]] ; then
rmlsend EX\ 999998\!
exit 0
fi