Archive of Posts from April 2006

Add a batch of dates to Google Calendar

I've always used several calendars to plan out my life. Until recently, I used a paper desk calendar to track work-related events like project milestones. I used an insanely hacked-up version of PHP Calendar to track daily appointments and travel plans. And I used a paper calendar hanging in the kitchen to track family events like birthdays and anniversaries. And to be honest, with all of the calendars I still wasn't very organized. The distinction between types of events and the calendars weren't as clear-cut as I'm describing them, and I'd often have a work project milestone on my kitchen calendar, or a birthday in PHP Calendar, not in their "proper" locations.

What I like about Google Calendar is the ability to lay several calendars on top of each other. So I can keep the family birthdays separate from the project milestones, but I can still show them all on one calendar if I need to. And with a click, I can remove the dates that aren't relevant for what I'm working on at the moment. The calendar list looks like this:

calendar controls

I decided to make Google Calendar my One Calendar To Rule Them All, and the switch has been very easy. The Ajaxy interface makes adding events insanely intuitive—click a day to add an event on that day. And I love the ability to click and drag several days to add weeklong events like conferences. The other big advantage to going digital is the ability to share calendars with other people. I can't easily send all of the data on my paper calendars to friends and family without Xerox and Fedex involved.

The one issue I ran into during the conversion was with family events. I had over 50 birthdays and anniversaries I wanted to add to a calendar, and the thought of clicking Create Event and adding data for each one, or worse—hunting and pecking to find a particular day to click—wasn't appealing. So I thought I'd share my method for dumping a bunch of dates into Google Calendar. You just need a little time to get your dates together, some Perl, and a Google Calendar account.


The Google Calendar doesn't have an API (yet), but it does have a hacker's little friend called import/export. Google accepts two types of calendar formats for import: iCalendar and Outlook's Comma Separated Values (CSV) export. So if you already have calendar data in Outlook or iCal you can simply import/export at will. (Yahoo! Calendar also exports to the Outlook CSV format, so switching is fairly painless.) But I didn't know the first thing about either of these formats, I simply had a list of dates I wanted to dump.

Gathering Dates

I had a head start because I already had a list of family birthdays and anniversaries in a text file. I massaged the list a little to get it into a data-friendly format, and ended up with a file full of dates that looked like this:
4/18/1942,Uncle Bob's Birthday
4/28/1944,Aunt Sally's Birthday
7/23/1978,Lindsay and Tobias' Anniversary
8/10/1989,Cousin Maeby's Birthday
(obviously not real data.)

If you're building a list of dates from scratch you can use Excel. Just put dates in the first column in mm/dd/yyyy format, descriptions in the second. When you're done, save the file in CSV format, ignoring all the warnings about compatibility.

I called the file family_dates.csv. Yes, this is a comma-separated value list too, but not the format Google Calendar is expecting. Plus you don't want to add an event on April 18th, 1942. You want to add a full day event for April 18th, each year going forward. This is where I turned to Perl to massage the data.

The Code

This simple Perl script: transformed the simple CSV list of dates and titles into the Outlook CSV format that Google likes to see. As you run the script it converts the year of the event into the current year, and adds an event for the next several years.

You'll need to customize the script a bit before you run it. Change $datefile to the name of your simple CSV file, in my case family_dates.csv. You can change $importfile to your preferred name of the output file, the default is import.csv. And you can set the number of years into the future that you'd like the date to appear by adjusting the value of $yearsahead, the default is 5. (If your events should only be added in the current year, set this to 1.)

Keep in mind that the larger the amount of data in your calendar, the longer it will take Google to load that calendar when you fire up Google Calendar. I originally set the $yearsahead value to 10, but with over 500 events, the calendar was noticably slowing the Google Calendar startup.

In addition to Perl, you'll need the standard Date::Calc module.

And if you're not in the US and would prefer dd/mm/yyyy format, simply change this bit: my ($month, $day) = to this: my ($day, $month) =. Instant internationalization!

Once everything is set, run the script from a command prompt, like this:


A new file called import.csv will magically appear with your dates formatted as Outlook CSV events. With the file in hand you can head over to Google Calendar.

Importing Data

Over at Google Calendar, click Manage Calendars under your calendar listing on the left site. Choose Create new calendar, and give your calendar a name and any other details. Click Create Calendar, and you'll see the new calendar in your list. Now click Settings in the upper right corner of the page, and choose the Import Calendar tab. Click Browse..., choose import.csv from your local files, set the calendar to your new calendar, and click Import.

That's all there is to it. You'll get a quick report about the number of events Google was able to import. Go back to your main view, and you should see your imported dates on the calendar, in the color of your newly created calendar. With one import, my view of April went from this:

calendar pre import

To this view with family birthdays the rust color:

calendar post import

(The details have been removed to protect the innocent.)

And once you have your calendar in Google, you can invite others to view and even help maintain the dates. Where I think this batch importing will be useful is for very large data sets. Imagine a teacher who wants to track the birthdays of students. It wouldn't be too hard to add the dates by hand. But a principal who wants to track the birthdays of everyone in a school will have an easier time putting together a spreadsheet than entering the days by hand. And even for my 50+ dates, writing a Perl script was preferable to entering the dates by hand.

So far I'm enjoying Google Calendar, and I haven't found any major problems beyond the limited importing ability. But now I really don't have an excuse for not sending out birthday cards.

Update (4/20): Google just released their Google Calendar API. I'll bet there are scores of hackers rushing to build bulk-import tools. Using the Calendar API would be a more stable way to import dates quickly. And wow! Hello, lifehackers!

Bloglines Update

Great news, Bloglines addressed the "onfocus/nofocus" problem and the Greasemonkey script I wrote isn't needed anymore. I got an email from Paul at Bloglines letting me know that, "Our anti-XSS code was being too aggresive and attempting to filter attribute values, in addition to attribute keys." Thanks, Paul! I'm very happy they took time out to address the problem because I think it's a great service and I didn't want to move to another reader. If you installed the Greasemonkey script, you can get rid of it. I deleted it from my server.

Flickr Hacks Code

There's a nice review of Flickr Hacks over at Hack Your Way Into Flickr, and the reviewer mentioned that the code for all of the hacks wasn't available online. O'Reilly has remedied the situation, and you can grab all of the code from the book in one zip file: Flickr Hacks Code. Carpal tunnels everywhere are rejoicing. (And don't forget about the color figures gallery at Flickr—another way to view parts of the book.)

Bloglines Greasemonkey Script

In January I posted about a peculiar problem between this site and Bloglines: Bloglines filtering. Basically, Bloglines filters out the word "onfocus" from links to avoid cross-site scripting (XSS) attacks. The filter isn't smart enough to realize that "" is perfectly ok, and not a threat. This means that anytime someone links to my site, or I link to images on my site, the Bloglines filter changes the domain from to When people click on a link to my site within Bloglines, they get a 404 error page at (System administrators over at must wonder why they get some strange 404 errors showing up in their logs.)

Anyway, I've emailed Bloglines about the problem several times and now I'm getting silence. I don't blame them, this is an obscure issue that only affects one of the millions of sites that flow through their system. But it still bugs me, so I wrote a quick Greasemonkey script to solve the problem. If you use Bloglines and Firefox and Greasemonkey, I encourage you to install this script: fix-bloglines-onfocus.user.js. (Of course, if you're reading this from within Bloglines, you'll need to visit directly to get the script.) The script changes any instance of "" to "". This script is as blunt as Bloglines' XSS filter, but it's my attempt to fix the issue from this end.

Many thanks to Mark Pilgrim for his Greasemonkey Patterns—it's a great resource for building scripts.

Update: Bloglines fixed their XSS filter.

Music Personality Score

Since talking with Gabriel at MusicStrands the other day, I've been thinking more about how we share our musical tastes with others. I was making the point to him that there should be a way to quickly relate the type of music you're interested in without forcing people to wade through months of listening data like the current social music services require. For example, you can see that my top two artists at are Bob Marley and Mozart based on frequency of plays, but that doesn't mean that my top two genres are Reggae and Classical. (I wouldn't place those as my top two if someone asked me.) You have to wade through the entire list to see that I also like classic rock, indie rock, electronic music, and lots of other genres.

What I was trying to say to Gabriel, but couldn't quite articulate, is that there should be a Myers-Briggs style scoring system for musical taste. When I see that someone is an ENFP, I have one instant measure of their personality. If you could do the same for music, you'd have a way to instantly relate your musical interests. I'm not sure what the criteria would be—maybe I'm an ISAE (indie structured ambient electronic), or MECR (mainstream eclectic classic rock). And this would go hand in hand with a service like MusicStrands because they can analyze the last 1,000 songs I actually listened to. With the score in hand, I could paste it into the dozen or so social network sites I belong to, giving people a more nuanced look at my preferences than my top 5 bands or something.

The iTunes Signature Maker is one stab at this concept. This application wades through your iTunes collection and creates a short audio signature based on the music it finds. When listening to others' signatures I guess you could listen for electronica vs. distorted guitars, but it doesn't really give you a sense of music preference. This is more of a fun hack than a useful way to share your musical identity. It'd be much more accurate to analyze what you're actually listening to, and then do a bit of categorization based on meta info about those tracks.

I [heart] NY

sk and I just got back from a week in New York—here are some snapshots. We ended up spending quite a bit of time just walking around New York City. Our first trek was through Central Park.

central park

Meg and Jason had a beautiful wedding, the reason for our trip.

meg and jason

On Sunday we took a bus to New Paltz, NY about an hour and half north of New York City to visit sk's aunt and uncle.

on the bus

We went on some great hikes in the area. Here's a picture sk snapped of me, apparently happy to be hiking.

pb hiking

The hiking highlight was a rock scramble up the side of a cliff, with great views from the top.

crag view

I'm hoping to make it back to New York City in the not too distant future. There's so much to do there and I feel like we barely scratched the surface.

no standing

You can see more photos from the trip (mostly from my cell phone) at Flickr, tagged with nyc and new paltz.