forked from jcschefer/sched
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsched
executable file
·40 lines (40 loc) · 1.46 KB
/
sched
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
#!/bin/bash
#
# NOTE: this is, without a doubt, the sketchiest and ugliest code
# i have ever written. please pipe all complaints regarding style,
# unreadability, inefficiency, or overall terribleness to /dev/null
#
# parse schedule as json
JSON="$(curl -s https://ion.tjhsst.edu/api/schedule?format=json)"
# regex json into class blocks
PARSE="$(echo $JSON | grep -Po '{\"order\":[^,]*,\"name\":[^,]*,\"start\":[^,]*,\"end\":[^}]*}')"
# split class blocks into array elements
readarray -t ARRAY <<<"$PARSE"
# some header stuff
DATE="$(echo $JSON | grep -Po '(?<=\"date\":\")[^,]*(?=\")')"
DAYNAME="$(echo $JSON | grep -Po '(?<=\"day_type\":{\"name\":\")[^,]*(?=\")')"
DATEPARSED="$(date --date="$DATE" "+%A, %B %d, %Y" )"
NOW="$(date "+%T")"
echo -e "\n$DATEPARSED"
echo -e "Time: $NOW"
echo -e "$DAYNAME\n"
# loop and print
for i in "${ARRAY[@]}"
do
# pull out name - replace <br> with space
NAME="$(echo $i | grep -Po '(?<=\"name\":\")[^\"]*' | sed 's/<br>/ /g'):"
#now pull times
START="$(echo $i | grep -Po '(?<=\"start\":\")[^\"]*' | sed 's/<br>/ /g')"
END="$(echo $i | grep -Po '(?<=\"end\":\")[^\"]*' | sed 's/<br>/ /g')"
STARTTIME="$(date --date="$START" "+%T" )"
ENDTIME="$(date --date="$END" "+%T" )"
if [[ "$NOW" > "$STARTTIME" && "$NOW" < "$ENDTIME" ]]
then
BOLD="$(tput setaf 1)"
NORMAL="$(tput sgr0)"
printf "${BOLD}%-25s %-5s - %-5s${NORMAL}\n" "$NAME" "$START" "$END"
else
printf "%-25s %-5s - %-5s\n" "$NAME" "$START" "$END"
fi
done
printf "\n"