Skip to content

Instantly share code, notes, and snippets.

@burtlo
Created September 5, 2012 22:07
Show Gist options
  • Save burtlo/3645949 to your computer and use it in GitHub Desktop.
Save burtlo/3645949 to your computer and use it in GitHub Desktop.
Sinatra with Sunlight
require 'csv'
require 'sunlight'
require 'sinatra'
Sunlight::Base.api_key = 'e179a6973728c4dd3fb1204283aaccb5'
representatives = Sunlight::Legislator.all_in_zipcode(90210)
filename = ARGV.first || "event_attendees.csv"
def clean_zipcode(zipcode)
# puts "#{other_options}"
zipcode.to_s.rjust(5,"a")
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
def representatives(filename)
options = {:headers => true, :header_converters => :symbol}
csv = CSV.open(filename,options)
people = csv.map do |line|
first_name = line[:first_name]
zipcode = clean_zipcode(line[:zipcode])
[ first_name, zipcode ]
end
information = people[0..20].map do |first_name,zipcode|
all_reps = all_reps(zipcode)
# all_reps = [ "Brayn", "Li", "Phredi" ]
"#{first_name} - #{all_reps.join(", ")}"
end
information
end
get '/' do
representatives(filename).join("<br/>")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment