Table of contents
- 1. Sunlight Labs API - Extension Manager
- 2. Sunlight Labs + Twitter
- 3. Top 5 Words Used By Barbara Boxer for the Month of January, 2009 /content/body/div[3]/h2/pre, reference to undefined name 'capital': line 2, column 17 (click for details)MindTouch.Deki.Script.DekiScriptUndefinedNameException: reference to undefined name 'capital': line 2, column 17 at MindTouch.Deki.Script.DekiScriptVar.Evaluate (MindTouch.Deki.Script.DekiScriptEnv env) [0x00000] at MindTouch.Deki.Script.DekiScriptAccess.Evaluate (MindTouch.Deki.Script.DekiScriptEnv env, Boolean evaluateProperties) [0x00000] at MindTouch.Deki.Script.DekiScriptAccess.Evaluate (MindTouch.Deki.Script.DekiScriptEnv env) [0x00000] at MindTouch.Deki.Script.DekiScriptCall.Evaluate (MindTouch.Deki.Script.DekiScriptEnv env) [0x00000] at MindTouch.Deki.Script.DekiScriptSequence.Evaluate (MindTouch.Deki.Script.DekiScriptEnv env) [0x00000] at MindTouch.Deki.Script.DekiScriptAssign.Evaluate (MindTouch.Deki.Script.DekiScriptEnv env) [0x00000] at MindTouch.Deki.Script.DekiScriptSequence.Evaluate (MindTouch.Deki.Script.DekiScriptEnv env) [0x00000] at MindTouch.Deki.Script.Dom.DekiScriptDomExpr.Evaluate (MindTouch.Deki.Script.DekiScriptEvalContext context, System.Xml.XmlNode parent, MindTouch.Deki.Script.DekiScriptEnv env) [0x00000] /content/body/div/@init, reference to undefined name 'capital': line 1, column 117 (click for details)MindTouch.Deki.Script.DekiScriptUndefinedNameException: reference to undefined name 'capital': line 1, column 117 at MindTouch.Deki.Script.DekiScriptVar.Evaluate (MindTouch.Deki.Script.DekiScriptEnv env) [0x00000] at MindTouch.Deki.Script.DekiScriptAccess.Evaluate (MindTouch.Deki.Script.DekiScriptEnv env, Boolean evaluateProperties) [0x00000] at MindTouch.Deki.Script.DekiScriptAccess.Evaluate (MindTouch.Deki.Script.DekiScriptEnv env) [0x00000] at MindTouch.Deki.Script.DekiScriptCall.Evaluate (MindTouch.Deki.Script.DekiScriptEnv env) [0x00000] at MindTouch.Deki.Script.DekiScriptSequence.Evaluate (MindTouch.Deki.Script.DekiScriptEnv env) [0x00000] at MindTouch.Deki.Script.DekiScriptAssign.Evaluate (MindTouch.Deki.Script.DekiScriptEnv env) [0x00000] at MindTouch.Deki.Script.DekiScriptSequence.Evaluate (MindTouch.Deki.Script.DekiScriptEnv env) [0x00000] at MindTouch.Deki.Script.Dom.DekiScriptDomBlock.Evaluate (MindTouch.Deki.Script.DekiScriptEvalContext context, System.Xml.XmlNode parent, MindTouch.Deki.Script.DekiScriptEnv env) [0x00000]
Sunlight Labs API - Extension Manager
Click on extension manager, Select Sunlight Labs, click on Sunlight.ZipTable, and enter a zip code. It will pop up with the legislators that are responsible for representing at least a portion of that zip code (formatted as a table). The information could also be retrieved as a list of maps that could be iterated through and mashed up if desired, but for now we've got a nice table.
Sunlight Labs + Twitter
First, we extract the Twitter ID obtained using the legislator function:
{{
var twitterID = (sunlight.legislator{lastname: "boxer"}.twitter_id)
}}
This returns:
Barbara_Boxer
We can then take that twitter ID (API call shown again in the top line), and get the last 5 tweets via the Twitter API. Note that I'm also formatting the tweets in an unordered list, using the foreach statement and web.html:
{{
var twitterID = (sunlight.legislator{lastname: "boxer"}.twitter_id);
var tweets = web.json('http://search.twitter.com/search.json?q=from:'..twitterID..'&rpp=5').results;
foreach (var tweet in tweets)
{
web.html('<ul><p>'..tweet.text..'</p></ul>')
}
}}
The end result is:
STAFF Sen Boxer appearing on Larry King tonight about 6:30 PT, 9:30 ET w/ Chelsea King's parents & discussing Violence Against Children Act
STAFF: The Senate passed a major new Jobs Bill this week. Check out the details. http://bit.ly/abozwG
STAFF: A thousand conservative activists will be at the California GOP Convention this weekend. Let's match them! http://bit.ly/cVzGdu
First, we need to get the Bioguide ID from the Sunlight API based on the last name (Capitol Words will only accept Bioguide IDs for legislator identification):
var bioguideId = (sunlight.legislator{lastname: "boxer"}.bioguide_id);
Then, using that Bioguide ID, I get the Barbara Boxer's 5 most-used words for the month January in this year:
var topWords = (capital.lawmakerTopWordsMonth{bioguideId: bioguideId, year: "2009", month: "1", words: "5"});
Finally, I take the words and wordcount returned from Capitol Words and format it as a Google Pie Chart (values being the wordcount, and the labels being the word itself):
google.PieChart{width: "650", height: "350", values: [topWords[0].word_count, topWords[1].word_count, topWords[2].word_count, topWords[4].word_count, topWords[4].word_count], labels:[topWords[0].word, topWords[1].word, topWords[2].word, topWords[3].word, topWords[4].word]};
The end result looks a bit like this:
Top 5 Words Used By Barbara Boxer for the Month of January, 2009
/content/body/div[3]/h2/pre, reference to undefined name 'capital': line 2, column 17 (click for details)

Comments