Adding dates from a spreadsheet to google calendar

My wife has lots of “on calls” and night shifts in her job.  No idea why they don’t make the rota available in a calendar-ready format such as iCal but they don’t – it’s an Excel spreadsheet.

Normally my wife goes through manually adding all her shifts to our shared google calendar, but I thought I’d help out (if I’d thought about it I would have done this sooner).  Using the very helpful googlecl (http://code.google.com/p/googlecl/) command line interface to google services I wrote this script to take dates as they appear in the spreadsheet and enter them into the calendar:

#!/bin/bash
# Add a set of dates copy and pasted from a spreadsheet to google calendar

username="yournamehere@gmail.com"
event_name="First on call"

dates=" 07-May
08-May
09-May
10-May
22-Jun
23-Jun
24-Jun
13-Aug
14-Aug
15-Aug
16-Aug
28-Sep
29-Sep
30-Sep
"

for date in $dates
do
    # Remove the dash from the above dates to get "24 Apr" so that Google cal
    # recognises it.  Bit of hack but seems to work
    date_formatted=${date/-/ }
    cal_entry="$date_formatted $event_name"
    google --user="$username" calendar add "$cal_entry"
done
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: