1
0
Fork 0
forked from OpenNeo/impress

rake task to update spotlight pets

This commit is contained in:
Emi Matchu 2011-12-20 21:00:02 -05:00
parent cc23f7435b
commit 91c1ac2acf

26
lib/tasks/spotlight.rake Normal file
View file

@ -0,0 +1,26 @@
require 'nokogiri'
namespace :spotlight do
desc "Update spotlight pets by HTML download of contest results"
task :update do |t, args|
input_path = args[:file]
unless input_path
raise ArgumentError, "provide FILE=/path/to/contest/results.html"
end
input_doc = File.open(input_path, 'r') { |file| Nokogiri::HTML(file) }
output_path = Rails.root.join('public', 'spotlight_pets.txt')
File.open(output_path, 'w') do |output_file|
links = input_doc.css('a[href^="/petlookup.phtml"]')
links.each do |link|
output_file.puts(link.text)
end
puts "Wrote #{links.size} names to #{output_path}"
end
end
end