Catch Sunlight at PyCon 2015 in Montreal — and help us build a new army of scrapers to collect data about political influence at all levels of government.
Continue readingHelp liberate your town’s info with the Open Civic Data project!
This Thanksgiving holiday, we're asking you to join Sunlight in helping create open data about your local government.
Continue readingNational Day of Civic Hacking 2013
This past weekend, over 11,000 individuals connected under the helm of the National Day of Civic Hacking (NDoCH) -- a series of local #HackForChange hackathons, unconferences, and meeting of the minds that engaged local communities with open data, code, and tech.
From what we can tell, the NDoCH events were magnetic, drawing together participation from local (and traveling) developers, government officials (including a few mayors!), community leaders, and even 21 federal agencies. The vibe of this national organization not only encouraged a sort of: "If you can't hack with the city you reside in, hack with the one you're physically located in," but also further encouraged cross-pollination of civic applications from community to community (For more highlights from the national scene, check out this Storify feed.) Although Sunlight wasn’t able to attend every one of the 95 events held this past weekend, the events we did attend taught us quite a bit. Below, we’ve rounded up our reflections, recaps, and geeky highlights from the festivities in Baltimore, DC, Montgomery County, North Carolina, and Western Massachusetts. Continue readingArt Hack Day Boston
A couple of weekends ago, I attended Art Hack Day
at Harvard. The event was put on by the
Big Bad Lab, where we were proud to provide
the data for the event through our APIs
It was a pleasure getting to show off
python-transparencydata
and (ok, I'm biased here) python-sunlight.
The creative juices were really flowing throughout the 3-day hackathon, folks
created some amazing projects, such as a vending machine bill acceptor that
sucked 100 dollar bills at the same rate money has been spent this election
cycle (it was really fast!), political speech karaoke, and a voting booth that just
can't accept "no". Some other creative projects included an app that would
process tweets from federal Senators and Representatives (twitter IDs found off the
Sunlight Congress API), and a
bulletin board was covered with flyers featuring (real!) numbers for lobbyists discovered through
Influence Explorer.
Introducing python-sunlight
Hello, World!
We'd like to welcome python-sunlight into the most excellent family of open-source projects maintained by Labs. This particular project aims to unify and normalize the Sunlight APIs into a single Python library that's easy to understand, use, and fun to play with.
This library currently supports our Congress API, Open States API, and Capitol Words API. As such we're deprecating the old python-sunlightapi and python-openstates libraries. They'll still work but will no longer be receiving updates, so switching is highly recommended.
This library has some neat features that should make migration painless - as well as some new features, such as a standardized location to place your Sunlight API Key, which makes testing (as well as distributing) your app even easier.
We've just released version 1.0.1 over on PyPI, which makes installation a snap on any system with pip
. The documentation is fairly complete, but feedback is super welcome -- we're eager to learn where folks get stuck.
Most of the bugs seemed to be worked out after the Boston Python Project Night, where we had a few folks test out the library. A special thanks to all our beta-testers!
Alright, so how do I get started?
Hacking on python-sunlight is super easy. Here's how to get setup.
You'll need an API key. If you've not done so, get an API key (it's alright, we'll wait, go ahead).
Back already? Great.
Now, you'll have gotten the email that has a long-ish string of letters and numbers - let's save this to ~/.sunlight.key
(where python-sunlight will look for a key). If you already had a key, it'd be worth it to go and dig it up.
If you're on a UNIX-type (MacOS, GNU/Linux, *BSD, AIX or Solaris (or any of the other POSIX-ey systems)) machine, you should be able to run a command that looks like the following:
echo "your-api-key-here" > ~/.sunlight.key
It's worth mentioning that your-api-key-here
should actually be your API key that was emailed to you up above.
Next, you should install python-sunlight via pip
. If pip
is not installed on your system, please download and install pip.
pip install sunlight
And you're good to go!
Without further ado, an example!
#!/usr/bin/env python
# Copyright (c) 2012, BSD-3 clause, Sunlight Labs
from sunlight import capitolwords
from sunlight import congress
phrase = "death metal"
# Today, we'll be printing out the Twitter IDs of all legislators that use
# this phrase most in the congressional record.
for cw_record in capitolwords.phrases_by_entity(
"legislator", # We're getting all legislators
sort="count", # sorted by how much they say
phrase=phrase, # this word
)[:6]: # We'll just try the top 5 legislators
legislator = congress.legislators(
bioguide_id=cw_record['legislator'], # Look up this biogude (unique ID)
# for every fed. legislator
all_legislators="true" # search retired legislators
)
if len(legislator) >= 1: # If we were able to find the legislator
legislator = legislator[0] # (this is a search, so it's a list)
if legislator['twitter_id'] != "": # and they have a Twitter ID
print "%s. %s (@%s) said %s %s times" % (
legislator['title'],
legislator['lastname'],
legislator['twitter_id'],
phrase,
int(cw_record['count'])
) # Print it to output :)
The output looks like this:
Sen. Feingold (@russfeingold) said death metal 979 times
Rep. Jackson Lee (@JacksonLeeTX18) said death metal 923 times
Sen. Leahy (@SenatorLeahy) said death metal 800 times
Sen. Kyl (@senjonkyl) said death metal 755 times
Sen. Durbin (@SenatorDurbin) said death metal 593 times
And once more (this time, searching for "san francisco"):
Rep. Filner (@CongBobFilner) said san francisco 1346 times
Sen. Feinstein (@senfeinstein) said san francisco 1288 times
Sen. Boxer (@senatorboxer) said san francisco 1181 times
Rep. Pelosi (@NancyPelosi) said san francisco 1135 times
Rep. Eshoo (@RepAnnaEshoo) said san francisco 677 times
Rock on!
Questions, concerns, bugs, patches, examples and virtual hugs are all welcome on our GitHub page, so please do check it out!
Continue reading