Google Calendar API v3

In one of my previous posts, I mentioned that I was using rainmeter to display useful information such as events in my google calendar on my desktop.

Google updated their calendar to API v3 sometime early this year and this broke the functionality. After waiting few months for a fix, and another few attempting to fix it here, I decided to write a simple version from scratch. I wrote a bash script to curl the ical file and performed a little sed/awk goodness. I then configured rainmeter to display the contents of the text file. For good measure, I setup cron to run the script every 30 minutes to update the calendar.

It may not look as pretty but at least it finally works.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
curl https://calendar.google.com/calendar/ical/<<INSERT YOUR URL HERE>>/basic.ics > basic.ics
awk '/^SUMMARY.*$/' basic.ics > basic2.ics #retain summary text and start event start date
sed -i 's/^........//' basic2.ics #remove SUMMARY: 
awk '/^DTSTART.*$/' basic.ics > basic3.ics
sed -i 's/........$//' basic3.ics
paste basic3.ics basic2.ics > basic.ics
awk '!/^.*VALUE=DATE.*$/' basic.ics > basic2.ics #some events in gcal have weird date notation
sed -i 's/:/: /g' basic.ics
sed -i 's/^.........//' basic.ics
DATE="$(date +'%Y%m%d')" #remove past events
awk 'int($1)>="'"$DATE"'"' basic.ics > basic2.ics
sort -k 1 basic2.ics > basic.ics
awk 'NR < 11' basic.ics > cal.ics #limit to 10 upcoming events
sed -i -e 's/^.\{4\}/&\//' cal.ics #add / after year and month 
sed -i -e 's/^.\{7\}/&\//' cal.ics
rm basic.ics #cleanup
rm basic2.ics
rm basic3.ics

The script can be found on github.

Edit (04/12/15): Google updated endpoint to calendar.google.com.