Monday, March 01, 2010

March Madness Challenge - Day 1

Several of my partners in craziness at FUBAR Labs, the local New Jersey Hackerpsace. Have taken on March Madness. Write a program a day for a month. Well I'm jumping in on day one with a piece of code that solves one of PIAs I experience when trying to get the emails off of Google Calendar Events. Wish there was a feature that allowed you to make a group based off of an event. Anyway, the following code is how to get a list of guests from a Google Calendar event. Pop the list into an alert box, then cut and paste for your own use.
---
/*
* Get list of emails address from the guests invited to a Google event
*/
(function () {
var guests, emails;
//Handily there is class associated to each guest
guests = document.getElementsByClassName("guest");
emails = "";
//iterate the guests
for (var i in guests)
{
if (guests.hasOwnProperty(i))
{
//each guest name/email is the first child textContent of guest element
emails = emails + guests[i].childNodes[0].textContent + ",\n";
}
}
alert(emails);
})();
---
In order to run this you need to can run it in the Firebug console. Testing this, you need to create a Google Calendar Event add a few people to it. Find an old event with people in the guest list.

Another way to run this would be as a Greasemonkey script. Hey, that might be a good project for tomorrow.

I did discover the source code for Google Hosted applications is not quite the same as it's standard gmail offerings. To run this in a hosted environment you would need to use the following to select the guests:

(function () {
var guests, emails, guest, tmp;
guests = document.getElementsByClassName("ep-gl-guest");
emails = "";
guest = "";
tmp = "";

for ( var i in guests)
{
if (guests.hasOwnProperty(i))
{
guest = guests[i].id;
tmp = guest.split(":i");
emails = emails + tmp[1] + ",\n";
}
}
alert(emails);
})();
//Final Note: Not Happy with editor at Blogger.com

No comments: