The Countdown on the homepage of this site (update: no longer used) is produced by using a script, run from the crontab. Thanks to a few folks on a certain irc channel for getting me past some mental blocks.
In cron, there is an entry which reads
*/15 * * * * ~/path/to/countdown ~/path/to/datafile > ~/path/to/outputfile
Countdown is shown below, it is a text file chmodded to 755. The datafile is a simple text file with the format
2006-11-23 :: Event Details 2006-12-14 14:23 :: Other Event 2005-09-23 :: \<a href\=\"http://www.murky.org/\"\>Go and look at Murk's Amazon Wishlist\</a\>
The times are optional, note that anything which BASH may misinterpret should be escaped, i.e. prefixed with /
The resulting file can be put into a webpage using a server side include, or some other means.
The data file will automatically be sorted into date order when the script is run. Please note that the script isn't really set up for repeating events. If anyone modifies the script to do this, I would be pleased to learn of the mod.
At some point, I want to limit it to the next N events only, this should be a simple modification, but I don't have the will right now! The script should not display events more than 24 hours old, nor should it display events more than a year hence (actually, it is a little less than a year)
I would also like to be able to specify when the item should appear, i.e. start to show the item 30 days before etc. The format for this would be:
date :: daysbefore :: Event
As an example:
2006-11-23 :: 30 :: Event Details 2006-12-14 14:23 :: 140 :: Other Event 2005-09-23 ::210 :: \<a href\=\"http://www.murky.org/\"\>Go and look at Murk's Amazon Wishlist\</a\>
This is probably the most desired mod from my point of view.
The repeating event mod would change the format to include R for repeat
2006-11-23 :: 30 R :: Event Details 2006-12-14 14:23 :: 140 :: Other Event 2005-09-23 ::210 R :: \<a href\=\"http://www.murky.org/\"\>Go and look at Murk's Amazon Wishlist\</a\>
Now, when an event is past the line would be deleted if there were no R present, and the year would be modified if there were. I imagine this would involve writing a new file line by line and then copying the new file over the old at the end. It would be up to the user to ensure there was a backup (it would not matter if it were outdated, as when pressed into use it would be modified!)
if [ -z "$1" ] ; then echo "I must have a filename to work with" exit 0 fi
# The Five Hours corrects the discrepancy between my server and me # MODIFY AS REQUIRED, My server is WEST of me uktime=$(date --date='5 hours' +%s) uktime2=$(date --date='5 hours' '+%B %d %H:%M')
sort $1 -o $1 echo "<ul class=\"module-list\">" # open file for reading exec 6<$1 # read until end of file while read -u 6 dta do event=$(echo $dta | sed "s@.*:: @@") whenisit=$(echo $dta | sed "s@::.*@@") optime=$(date --date="$whenisit" +%s) optime=$(($optime-$uktime)) if expr \( $optime \< 0 \) > /dev/null then optime=-$optime hours=$((optime/3600)) if [ $hours \< 24 ] then echo "<li>$event" echo " <span class=\"dateline\">(passed within last 24hrs)</span></li>" fi else year=$((optime/30000000)) # this will suppress any events more than a little less than a year off if expr \( $year \< 1 \) > /dev/null then echo -n "<li>$event <span class=\"dateline\">(" secs=$((optime%60)) mins=$((optime/60)) optime=$mins if expr \( $mins \< 60 \) > /dev/null then echo -n "$mins minutes and $secs seconds." else mins=$((optime%60)) hours=$((optime/60)) optime=$hours if expr \( $hours \< 24 \) > /dev/null then echo -n "$hours hour" if [ $hours != 1 ] then echo -n "s" fi #pluralisation echo -n ", $mins mins" else hours=$((optime%24)) days=$((optime/24)) optime=$days echo -n "$days day" if [ $days != 1 ] then echo -n "s" fi #pluralisation echo -n ", $hours hour" if [ $hours != 1 ] then echo -n "s" fi #pluralisation fi #hours fi #minutes echo ")</span></li>" fi #check that it isn't too far fi done
echo "<li class=\"lastupdate\">lastupdated: $uktime2 UK</li>" echo "</ul>"
# close file test.data exec 6<&-