Skip to content

Instantly share code, notes, and snippets.

@burtlo
Created September 5, 2012 18:26
Show Gist options
  • Save burtlo/3642014 to your computer and use it in GitHub Desktop.
Save burtlo/3642014 to your computer and use it in GitHub Desktop.
Using the Sunlight API
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