Last active
August 29, 2015 13:59
-
-
Save jcasimir/10936252 to your computer and use it in GitHub Desktop.
This file contains 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 'json' | |
output = `curl -X GET 'http://congress.api.sunlightfoundation.com/legislators/locate?zip=80209&apikey=e179a6973728c4dd3fb1204283aaccb5'` | |
data = JSON.parse(output) |
This file contains 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/congress' | |
require 'erb' | |
puts "EventManager Initialized!" | |
Sunlight::Congress.api_key = ENV['SUNLIGHT_API_KEY'] | |
def clean_zipcode(data) | |
data ||= '00000' | |
data.rjust(5, '0') | |
end | |
def legislators_for_zipcode(zipcode) | |
Sunlight::Congress::Legislator.by_zipcode(zipcode).map do |leg| | |
"#{leg.first_name} #{leg.last_name}" | |
end | |
end | |
contents = CSV.open("event_attendees.csv", :headers => true, | |
:header_converters => :symbol) | |
template = File.read("form_letter.html.erb") | |
erb_template = ERB.new(template) | |
contents.each do |line| | |
zipcode = clean_zipcode(line[:zipcode]) | |
legislators = legislators_for_zipcode(zipcode) | |
first_name = line[:first_name] | |
final_content = erb_template.result(binding) | |
output = File.open("thank_you_#{line[0]}.html", "w") | |
output.write(final_content) | |
output.close | |
end |
This file contains 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
<html> | |
<head> | |
<meta charset='utf-8'> | |
<title>Thank You!</title> | |
</head> | |
<body> | |
<h1>Thanks <%= first_name %>!</h1> | |
<p>Thanks for coming to our conference. We couldn't have done it without you!</p> | |
<p> | |
Political activism is at the heart of any democracy and your voice needs to be heard. | |
Please consider reaching out to your following representatives: | |
</p> | |
<table> | |
<tr><th>Legislators</th></tr> | |
<% legislators.each do |legislator| %> | |
<tr><td><%= legislator %></td></tr> | |
<% end %> | |
</table> | |
</body> | |
</html> |
This file contains 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
desc "It's says 'Hey'" | |
task :say_hey do | |
`say hey` | |
end | |
desc "It says 'Hey you'" | |
task :say_hey_you => [:say_hey] do | |
`say you` | |
end | |
desc "It says hey to someone" | |
task :say_hey_to => [:say_hey] do | |
`say #{ENV['NAME']}` | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment