Difference between revisions of "T1042 CLI Script"

From CDOT Wiki
Jump to: navigation, search
(Redirected page to SICT AR Meeting Area CLI Script)
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
 +
 +
#REDIRECT [[SICT AR Meeting Area CLI Script]]
 +
 +
== Script ==
 +
 
This is a bash script to display the t1042 bookings for a given day:
 
This is a bash script to display the t1042 bookings for a given day:
  
 
  #!/bin/bash
 
  #!/bin/bash
 
  #
 
  #
  # Script to display bookings in T1042.
+
  # Script to display bookings in T1042/DB1042
 
  # Give a datespec on the command line, or no args for today.
 
  # Give a datespec on the command line, or no args for today.
 
  #
 
  #
Line 18: Line 23:
 
  }
 
  }
 
   
 
   
 +
function check_day() {
 +
date -d "$*" >&/dev/null
 +
return $?
 +
}
 +
 +
function usage() {
 +
exec >&2
 +
echo "Invalid dateSpecification."
 +
echo "Usage: $(basename $0) [-w] dateSpecification"
 +
echo "Where: dateSpecification is valid date (e.g., 2038-01-01 or Next Tuesday)"
 +
echo "        -w  causes a full week to be output."
 +
exit 1
 +
}
 +
 
  if  grep -qi t1042 <<<$0  
 
  if  grep -qi t1042 <<<$0  
 
  then
 
  then
Line 24: Line 43:
 
  ROOMNAME="DB1042" # new name
 
  ROOMNAME="DB1042" # new name
 
  fi
 
  fi
 +
 +
trap "rm \$TEMPFILE" SIGHUP SIGINT EXIT
 
   
 
   
 
  TEMPFILE=$(mktemp)
 
  TEMPFILE=$(mktemp)
Line 33: Line 54:
 
  then
 
  then
 
  shift
 
  shift
  echo "${ROOMNAME} schedule for the week of $(date -d "$*" +%Y-%m-%d):"
+
for X in {0..6}
+
if check_day "$*"
do
+
  then
echo  
+
echo "${ROOMNAME} schedule for the week of $(date -d "$*" +%Y-%m-%d):"
date -d "$(( X - $(date +%w) )) day" +"  %A:"
+
for X in {0..6}
show_day "$(date -d "$(date -d "$*") + $(( X - $(date +%w) )) day")"
+
do
  done
+
echo  
 +
date -d "$(( X - $(date +%w) )) day" +"  %A:"
 +
show_day "$(date -d "$(date -d "$*") + $(( X - $(date +%w) )) day")"
 +
done
 +
  else
 +
usage
 +
exit 1
 +
fi
 
  else
 
  else
  echo "${ROOMNAME} schedule for $(date +%Y-%m-%d -d "$*"):"
+
  if check_day "$*"
show_day "$@"
+
then
 +
echo "${ROOMNAME} schedule for $(date +%Y-%m-%d -d "$*"):"
 +
show_day "$@"
 +
else
 +
usage
 +
exit 1
 +
fi
 +
 
  fi
 
  fi
 
  echo
 
  echo
+
 
rm $TEMPFILE
+
 
 +
== Usage Examples ==
  
 
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:
Line 67: Line 103:
  
 
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.
 
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.
 +
 +
== Contribute ==
 +
 +
To contribute to development of this script, see the GitHub repository at https://github.com/Seneca-CDOT/t1042
  
 
<!-- THE CODE BELOW MAY PREVENT LINES FROM APPEARING IF THEY HAVE UNLINKED OR MISSING CONTACT DATA -- *FIXME*
 
<!-- THE CODE BELOW MAY PREVENT LINES FROM APPEARING IF THEY HAVE UNLINKED OR MISSING CONTACT DATA -- *FIXME*

Latest revision as of 21:10, 9 February 2019

Script

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

#!/bin/bash
#
# Script to display bookings in T1042/DB1042
# 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
}

function check_day() {
	date -d "$*" >&/dev/null 
	return $?
}
	
function usage() {
	exec >&2
	echo "Invalid dateSpecification."
	echo "Usage: $(basename $0) [-w] dateSpecification"
	echo "Where: dateSpecification is valid date (e.g., 2038-01-01 or Next Tuesday)"
	echo "        -w   causes a full week to be output."
	exit 1
}
	
if  grep -qi t1042 <<<$0 
then
	ROOMNAME="T1042" # traditional name
else
	ROOMNAME="DB1042" # new name
fi

trap "rm \$TEMPFILE" SIGHUP SIGINT EXIT

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

echo

if [ "$1" == "-w" ]
then
	shift

	if check_day "$*"
	then
		echo "${ROOMNAME} 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
		usage
		exit 1
	fi
else
	if check_day "$*"
	then	
		echo "${ROOMNAME} schedule for $(date +%Y-%m-%d -d "$*"):"
		show_day "$@"
	else
		usage
		exit 1
	fi

fi
echo


Usage Examples

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 2020-02-01
t1042 june 7, 2025

You can also specify a -w argument to see a week at a time:

t1042 -w
t1042 -w next week
t1042 -w may 1

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.

Contribute

To contribute to development of this script, see the GitHub repository at https://github.com/Seneca-CDOT/t1042