Saturday, 9 October 2010

[Update] A Simple Reminder System

This is an update to my last post A Simple Reminder System
Scanning the technical news I recently came across: gcalcli. Can this be used with my reminder system? Well, yes it can! Very simply in fact. It took a short Bourne shell script which reads calendar entries forward from today, then post them to Google Calendars. This is the script:
#!/bin/sh
# Update Google calendar with local calendar.
#
# $Id: syncgcal.sh 706 2010-10-09 05:28:44Z frank $
echo -n 'Reading calendar events ...'
forwardDate=`/bin/date --date="+7 days" "+%Y%m%d"`
/usr/bin/calendar -t $forwardDate | while read entry
do
   /usr/bin/gcalcli quick "$entry"
done
echo ' done!'
exit 0
The trick used here is to check upcoming events for a fixed number of days forward.  If you use calendar -A then you'll get events repeated. This is a compromise: checking only a fixed number of days forward and posting items for that date only. What would be better, would be to identify changed entries and just posting them. To do this you need to have a additional data store of posted events and lots more code. Maybe next time. I will trial the current set-up and see how it goes.

The gcalcli command uses a Python style configuration file of ~/.gcalcli. This is where you can record user, password and calendar defaults for your Google calendar. Not surprising as gcacli is written in Python.
Finally, add a cron table entry:
@daily ~/bin/syncgcal | /usr/bin/mail -e -s "Google calendar updates" your_user@localhost
This will daily invoke calendar updates. The results are locally emailed back to you, which is useful for testing.

No comments: