I read earlier this week about a new application contest being sponsored by SunlightLabs called Apps for America. You can read more details on their site, but the idea is to encourage developers to create open source applications that increase awareness and transparency in government. I started thinking about a few ideas for applications, and while the SunlightLabs API provides details for each legislator like website, email, Twitter, and YouTube URLs, what I really wanted to know was my representatives’ RSS or Atom feed.
Turns out, that information isn’t provided by the SunlightLabs API, but that doesn’t mean we can’t find it. As it turns out, there’s a function in the Google AJAX Feed API to submit a general URL and then receive information back if there’s an RSS or Atom feed associated with the URL. So let’s mashup those two services and find our answer.
In this example, I’m going to do it just using Javascript running on a webpage. The webpage will contain a single textarea element named ‘output’ where we’ll display the results.
The Javascript for this is very straightforward. First, we’ll initialize our variables and Google services.
var legislators;
var currentRep = -1;
var sunlightAPIcall = "legislators.getList.json";
// replace this with your full API key for Sunlight Labs
google.load("jquery", "1");
google.load("feeds", "1");
Then using jQuery, we’ll grab the details about ALL the legislators from SunlightLabs and store the result in a variable.
function initialize() {
$.getJSON(sunlightAPIcall, function (data) {
if (data.response.legislators && data.response.legislators.length > 0) {
legislators = data.response.legislators;
checkNextFeed();
}
});
}
Next, we need to check each representative to see if they even have a website.
function checkNextFeed() {
do {
currentRep++;
} while ((currentRep < legislators.length) && (legislators[currentRep].legislator.website == ""));
document.getElementById("output").value = currentRep + " / " + legislators.length;
setTimeout(lookupNextFeed,100);
}
If the legislator has a website, then we'll use the Google API to lookup the feed, or if we're at the end of the list, then we'll print out the results.
function lookupNextFeed() {
if (currentRep < legislators.length) {
google.feeds.lookupFeed(legislators[currentRep].legislator.website, lookupFeedDone);
} else {
outputResults();
}
}
Once Google is done checking for the feed, it returns the results to our lookupFeedDone() function and we store the result in a new field of the object. Then, we start the process all over for the next legislator.
function lookupFeedDone(result) {
if (result.url) {
legislators[currentRep].legislator.feed = result.url;
} else {
legislators[currentRep].legislator.feed = "";
}
checkNextFeed();
}
Finally, here's the function to print out the results.
function outputResults() {
var csv = "bioguide_id,website,feed\n";
for (var i=0; i < legislators.length; i++) {
csv = csv + legislators[i].legislator.bioguide_id + ","
+ legislators[i].legislator.website
+ "," + legislators[i].legislator.feed + "\n";
}
document.getElementById("output").value = csv;
}
So what do the results look like? Well,
- There are 540 legislators
- There are 473 legislators with websites
- There are 109 legislators with data feeds
That's helpful, but it's still pretty sad that only 20% of legislators provide content in a feed format. Perhaps you should send them an email and ask them to update?
In the meantime, here's some links for you:
- Download a list of all the representatives' feeds (CSV format, generated Jan 2009)
- Download full source code of this example (*note you'll need your own Google API key and SunlightLabs API key in order for it to work)
- Lookup your representative
- Email your representative
UPDATE: Turns out some of the feeds are invalid (pointing to htmlfixit.com). Here's the full list of feeds as rendered by the Goog, I'm sure as comments come in, we'll update the list some more:
- Rep. Neil Abercrombie [D, HI-1]
- Rep. Gary Ackerman [D, NY-5]
- Rep. Robert Aderholt [R, AL-4]
- Rep. Michael Arcuri [D, NY-24]
- Rep. Joe Barton [R, TX-6]
- Rep. Robert Marion Berry [D, AR-1]
- Rep. Brian Bilbray [R, CA-50]
- Rep. Earl Blumenauer [D, OR-3]
- Rep. John Boehner [R, OH-8]
- Sen. Richard Burr [R, NC-Senior Seat]
- Rep. Dan Burton [R, IN-5]
- Rep. Judy Biggert [R, IL-13]
- Rep. Henry Brown [R, SC-1]
- Rep. J. Gresham Barrett [R, SC-3]
- Rep. Timothy Bishop [D, NY-1]
- Rep. Michael Burgess [R, TX-26]
- Sen. C. Saxby Chambliss [R, GA-Senior Seat]
- Rep. John Coble [R, NC-6]
- Rep. John Conyers [D, MI-14]
- Rep. Jerry Costello [D, IL-12]
- Rep. Elijah Cummings [D, MD-7]
- Rep. Henry Cuellar [D, TX-28]
- Rep. Yvette Clarke [D, NY-11]
- Rep. Joseph Courtney [D, CT-2]
- Rep. Diana DeGette [D, CO-1]
- Rep. Norman Dicks [D, WA-6]
- Rep. John Dingell [D, MI-15]
- Sen. Christopher Dodd [D, CT-Senior Seat]
- Rep. Michael Doyle [D, PA-14]
- Rep. John Duncan [R, TN-2]
- Sen. Jim DeMint [R, SC-Junior Seat]
- Rep. Lincoln Davis [D, TN-4]
- Rep. Mario Diaz-Balart [R, FL-25]
- Rep. Joe Donnelly [D, IN-2]
- Sen. John Ensign [R, NV-Junior Seat]
- Rep. Trent Franks [R, AZ-2]
- Rep. Jeff Fortenberry [R, NE-1]
- Rep. Virginia Foxx [R, NC-5]
- Rep. Bart Gordon [D, TN-6]
- Rep. Kay Granger [R, TX-12]
- Rep. Luis Gutierrez [D, IL-4]
- Rep. Samuel Graves [R, MO-6]
- Rep. Raúl Grijalva [D, AZ-7]
- Rep. Walter Herger [R, CA-2]
- Rep. Maurice Hinchey [D, NY-22]
- Rep. Rubén Hinojosa [D, TX-15]
- Rep. Tim Holden [D, PA-17]
- Rep. Rush Holt [D, NJ-12]
- Rep. Michael Honda [D, CA-15]
- Rep. Jeb Hensarling [R, TX-5]
- Rep. Phil Hare [D, IL-17]
- Rep. Mazie Hirono [D, HI-2]
- Rep. Darrell Issa [R, CA-49]
- Rep. Steve Israel [D, NY-2]
- Rep. Sheila Jackson Lee [D, TX-18]
- Rep. Samuel Johnson [R, TX-3]
- Rep. Jesse Jackson [D, IL-2]
- Rep. Jack Kingston [R, GA-1]
- Rep. Zoe Lofgren [D, CA-16]
- Rep. Nita Lowey [D, NY-18]
- Rep. Frank Lucas [R, OK-3]
- Rep. Daniel Lungren [R, CA-3]
- Rep. Barbara Lee [D, CA-9]
- Rep. James Langevin [D, RI-2]
- Rep. Stephen Lynch [D, MA-9]
- Rep. Edward Markey [D, MA-7]
- Rep. Carolyn McCarthy [D, NY-4]
- Rep. James McGovern [D, MA-3]
- Rep. Howard McKeon [R, CA-25]
- Rep. George Miller [D, CA-7]
- Rep. James Moran [D, VA-8]
- Rep. Gregory Meeks [D, NY-6]
- Rep. Dennis Moore [D, KS-3]
- Rep. Kendrick Meek [D, FL-17]
- Rep. Ralph Miller [D, NC-13]
- Rep. Michael McCaul [R, TX-10]
- Rep. Kenny Marchant [R, TX-24]
- Rep. Gwendolynne Moore [D, WI-4]
- Rep. Gerald McNerney [D, CA-11]
- Rep. Randy Neugebauer [R, TX-19]
- Rep. Frank Pallone [D, NJ-6]
- Rep. Thomas Petri [R, WI-6]
- Rep. Ronald Paul [R, TX-14]
- Rep. Nick Joe Rahall [D, WV-3]
- Rep. Silvestre Reyes [D, TX-16]
- Rep. Ileana Ros-Lehtinen [R, FL-18]
- Rep. Edward Royce [R, CA-40]
- Rep. Bobby Rush [D, IL-1]
- Rep. Mike Ross [D, AR-4]
- Rep. Michael Rogers [R, AL-3]
- Rep. David George Reichert [R, WA-8]
- Rep. Laura Richardson [D, CA-37]
- Rep. Robert Scott [D, VA-3]
- Rep. Victor Snyder [D, AR-2]
- Sen. Debbie Stabenow [D, MI-Junior Seat]
- Rep. Fortney Stark [D, CA-13]
- Rep. Janice Schakowsky [D, IL-9]
- Rep. Zachary Space [D, OH-18]
- Rep. Stephen Scalise [R, LA-1]
- Rep. Todd Tiahrt [R, KS-4]
- Rep. John Tierney [D, MA-6]
- Rep. Edolphus Towns [D, NY-10]
- Rep. Lee Terry [R, NE-2]
- Rep. Michael Thompson [D, CA-1]
- Rep. Nicola Tsongas [D, MA-5]
- Rep. Frank Wolf [R, VA-10]
- Rep. Greg Walden [R, OR-2]
- Rep. David Wu [D, OR-1]
- Rep. John Yarmuth [D, KY-3]
|
randy |
fucking pathetic
Clay Johnson |
This is really great! Awesome work. Maybe we can incorporate this into the Sunlight Labs API.
Joe Germuska |
I was trying to do some stuff with your data and found that there are ten cases where you have apparently valid feed URLs in your CSV file, but parsing that feed results in 0 entries. Checking further revealed that 9 of the 10 have problems with the autodiscovered RSS feed, and the tenth (Conyers) just should have been more careful with the redirects when moving the site to “conyers.house.gov”
Burr[B001135] feed URL is different [http://burr.senate.gov/public/index.cfm?FuseAction=RSS.Feed], but all entries have relative URLs which don’t load.
Conyers[C000714] website URL and feed URL have changed. With updated values, all is OK. [http://conyers.house.gov/, http://conyers.house.gov/index.cfm?FuseAction=RSS.Feed
Costello[C000794] autodiscovered feed URL is 404
Cuellar[C001063] feed URL returns invalid XML
Davis[D000599] autodiscovered feed URL is 404
Ensign[E000194] same as Burr, feed URL is different [http://ensign.senate.gov/public/index.cfm?FuseAction=RSS.Feed] but entries have relative URLs which don’t load
Hensarling[H001036] autodiscovered feed URL is 404
Holden[H000712] autodiscovered feed URL is 404
Johnson[J000174] same as Cuellar: feed URL returns invalid XML
Tierney[T000266] autodiscovered feed URL returns 403 Forbidden
So after taking out those, the “undefined” and the “htmlfixit” feeds in your datafile, I’m down to only 78 legislators having feeds. Still, this is a great way to draw attention to the issue.
Dan |
I enjoyed reading the article walking through the approach you used.
You should consider deleting that initial comment, listed as comment 1 from 1/22. Its not constructive.