forked from OpenNeo/impress
rake task to update spotlight pets
This commit is contained in:
parent
cc23f7435b
commit
91c1ac2acf
1 changed files with 26 additions and 0 deletions
26
lib/tasks/spotlight.rake
Normal file
26
lib/tasks/spotlight.rake
Normal 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
|
Loading…
Reference in a new issue