Talking rabbit reminders with Nabaztag and Google Calendar

At ReignDesign we use a shared Google Calendar to help plan our schedules. Todd previously wrote about Reigndesign's rabbit Nabby. What if there was a way to get Nabby to remind us about our upcoming appointments? Both Nabby and Google Calendar have simple APIs, and other folks have already written client libraries for PHP, so the amount of "glue" required to make it work was surprisingly small!

Ingredients

normal.nabby

Method

In Google Calendar, find the calendar you want your Nabaztag to make announcements for. Click the down arrow by the name and choose Calendar settings.

calsettings

Then right click and copy the link for the iCal private URL.

calical

Create a folder for your PHP project, and create a PHP file as follows:

  1.  
  2. /**
  3. Nabaztag-Google Calendar mashup!
  4. */
  5. require("icalparser/SG_iCal.php"); //ical parser
  6. require("Nabaztag.class.php"); //nabaztag class - define your api key and secret in here
  7. $nabby=new Nabaztag;
  8. $parser=new SG_iCal('http://www.google.com/calendar/ical/.....'); //url of calendar
  9. $events=($parser->getEvents());
  10. foreach ($events as $event) {
  11. $ttl=($event->getStart()-time())/60;
  12. if ($ttl>0 && $ttl<15) {
  13. //it's starting soon!
  14. $uid=$event->getUID();
  15. if (!file_exists("uids/".$uid)) {
  16. //we haven't yet announced this event
  17. $data="Reminder: the event ".$event->getSummary()." is starting in ".round($ttl)." minutes";
  18. //write to a file to avoid announcing twice
  19. file_put_contents("uids/".$uid,$data);
  20. //call the nabby api
  21. $nabby->talk($data,'US-Ernest');
  22. }
  23. }
  24. }
  25.  

This should be pretty self-explanatory. We loop through the events in the iCal document, looking for any events where the start time is in the next 15 minutes. If we find any, we send some text to the Nabaztag API to speak out loud. Then, we write to a file with the UID of the event to ensure we don't announce the same event several times.

A few housekeeping bits and pieces:

  • create an empty uids folder
  • on Linux you'll need to chmod a+w uids to ensure it's writable
  • set up a cronjob (Linux) or scheduled task (Windows) to run the PHP script as often as you want (say, every 2 or 5 minutes).

Success! A few minutes before your event is due, Nabby will now announce something like Reminder: the event "Lunch 2.0" is starting in 13 minutes.

Listen (mp3 format)

Matt Mayer

Matt Mayer is a founder at ReignDesign. Matt is from the UK and was based in Shanghai for ten years. He is now living in Bangkok, Thailand.

1 comment

  1. Great idea! I was looking for something new to do with my rabbit, and Google calendar has replaced the old calendar on the ‘fridge in our house. I put together an implementation in python using the google calendar python api rather than ical. I set mine up just to read the events for the day once in the morning, but same concept.

Leave a Reply

Your email address will not be published. Required fields are marked *