Difference between revisions of "T1042 CLI Script"

From CDOT Wiki
Jump to: navigation, search
Line 7: Line 7:
 
  #
 
  #
 
  # CTyler 2015-05-13, updated after wiki move 2016-08-05
 
  # CTyler 2015-05-13, updated after wiki move 2016-08-05
 +
# updated with -w argument (week) 2017-01-30
 
  #
 
  #
 
   
 
   
  echo "T1042 schedule for $(date +%Y-%m-%d -d "$*"):"
+
  function show_day() {
 +
        cat $TEMPFILE|
 +
        egrep "</?td|</?tr"|tr -d "\012"|
 +
        sed "s|</tr><tr>|</tr>\n<tr>|g"|
 +
        sed -n "s|<tr><td>$(date +%Y-%m-%d -d "$*") \([0-2][0-9]:[0-5][0-9]-[0-2][0-9]:[0-5][0-9]\)</td><td>\([^<]\+\)</td>.*$|    \1 \2|p"|
 +
        sort
 +
}
 
   
 
   
  curl https://wiki.cdot.senecacollege.ca/wiki/Meeting_Room_T1042 2>/dev/null|
+
TEMPFILE=$(mktemp)
  egrep "</?td|</?tr"|tr -d "\012"|
+
  curl https://wiki.cdot.senecacollege.ca/wiki/Meeting_Room_T1042 2>/dev/null >$TEMPFILE
  sed "s|</tr><tr>|</tr>\n<tr>|g"|
+
sed -n "s|<tr><td>$(date +%Y-%m-%d -d "$*") \([0-2][0-9]:[0-5][0-9]-[0-2][0-9]:[0-5][0-9]\)</td><td>\([^<]\+\)</td>.*$| \1 \2|p"|
+
echo
  sort
+
   
 +
if [ "$1" == "-w" ]
 +
  then
 +
        shift
 +
        echo "T1042 schedule for the week of $(date -d "$*" +%Y-%m-%d):"
 +
        for X in {0..6}
 +
        do
 +
                echo
 +
                date -d "$(( X - $(date +%w) )) day" +"  %A:"
 +
                show_day "$(date -d "$(date -d "$*") + $(( X - $(date +%w) )) day")"
 +
        done
 +
else
 +
        echo "T1042 schedule for $(date +%Y-%m-%d -d "$*"):"
 +
        show_day "$@"
 +
fi
 +
echo
 +
   
 +
  rm $TEMPFILE
 +
 
  
 
To use this script, run it with no arguments for the current day, or specify a day:
 
To use this script, run it with no arguments for the current day, or specify a day:

Revision as of 10:49, 30 January 2018

This is a bash script to display the t1042 bookings for a given day:

#!/bin/bash
#
# Script to display bookings in T1042.
# Give a datespec on the command line, or no args for today.
#
# CTyler 2015-05-13, updated after wiki move 2016-08-05
# updated with -w argument (week) 2017-01-30
#

function show_day() {
        cat $TEMPFILE|
        egrep "</?td|</?tr"|tr -d "\012"|
        sed "s|</tr><tr>|</tr>\n<tr>|g"|
        sed -n "s|<tr><td>$(date +%Y-%m-%d -d "$*") \([0-2][0-9]:[0-5][0-9]-[0-2][0-9]:[0-5][0-9]\)</td><td>\([^<]\+\)</td>.*$|    \1 \2|p"|
        sort
}

TEMPFILE=$(mktemp)
curl https://wiki.cdot.senecacollege.ca/wiki/Meeting_Room_T1042 2>/dev/null >$TEMPFILE

echo

if [ "$1" == "-w" ]
then
        shift
        echo "T1042 schedule for the week of $(date -d "$*" +%Y-%m-%d):"
        for X in {0..6}
        do
                echo 
                date -d "$(( X - $(date +%w) )) day" +"  %A:"
                show_day "$(date -d "$(date -d "$*") + $(( X - $(date +%w) )) day")"
        done
else
        echo "T1042 schedule for $(date +%Y-%m-%d -d "$*"):"
        show_day "$@"
fi
echo

rm $TEMPFILE


To use this script, run it with no arguments for the current day, or specify a day:

t1042
t1042 tomorrow
t1042 yesterday
t1042 next friday
t1042 next week friday
t1042 last tuesday
t1042 may 15
t1042 2016-02-01
t1042 june 7, 2018

The data displayed is taken from the Meeting Room T1042 page on this wiki, and the date and times must be formatted correctly (YYYY-MM-DD HH:MM-HH:MM) to display.