Created
September 5, 2012 18:26
-
-
Save burtlo/3642014 to your computer and use it in GitHub Desktop.
Using the Sunlight API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'csv' | |
require 'sunlight' | |
Sunlight::Base.api_key = 'e179a6973728c4dd3fb1204283aaccb5' | |
filename = ARGV.first || "event_attendees.csv" | |
options = {:headers => true, :header_converters => :symbol} | |
def clean_zipcode(zipcode) | |
# puts "#{other_options}" | |
zipcode.to_s.rjust(5,"0") | |
end | |
def all_reps(zipcode) | |
representatives = Sunlight::Legislator.all_in_zipcode(zipcode) | |
representatives.map do |rep| | |
"#{rep.firstname[0]}. #{rep.lastname} (#{rep.party})" | |
end | |
end | |
csv = CSV.open(filename,options) | |
csv.each do |line| | |
first_name = line[:first_name] | |
zipcode = clean_zipcode(line[:zipcode]) | |
all_reps = all_reps(zipcode) | |
puts "#{first_name} - #{all_reps.join(", ")}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment