Friday, June 8, 2007

The GData API and "Web Content"

As mentioned previously, recently I wrote a script to scrape the UV Index forecast for London off of the TEMIS website and then upload that data into Google Calendar as a bunch of events that have associated "web content", that way there will be a little coloured box on the top of each day, and hovering over the box will give the numerical value for the forecasted UV Index for that day.

It was, for the most part, fairly straight forward (even though I used the "raw" Google Data Java API and not the sugared API that's available for groovy). The biggest issue I ran into was that the API doesn't like WebContent that doesn't have a content URL set. According to the documentation at Google's Help Center, a content URL is optional. A content URL is the URL for content that will be displayed when the user clicks on the icon for the event, which isn't always necessary (such as with the weather forecast). However, trying to insert an event with WebContent using the Java API that doesn't have a content URL always resulted in 404 ResourceNotFound errors. Putting in a URL was the only way to get it working, so I quickly created an about.html that displays a copyright notice indicating that the data is from TEMIS (which is a good thing to have anyway).

The coloured boxes were whipped up with ImageMagick, the colours are based on the colours used in the wikipedia article on the UV Index. The coloured box that gets displayed is dependent on the forecasted UV Index.

The calendar can be found here. If you add it to your own set of calendars, you'll probably have to hit the refresh button to get the boxes to display.

One other thing, that I'm not sure is mentioned elsewhere, but the API needed the Java Mail API (javx.mail) on the classpath. So I had to download it from Sun.

No comments: