Created
September 15, 2009 20:19
-
-
Save railsfactory/187608 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
module Handler | |
def file_modified | |
puts "#{path} modified" | |
lines = File.read(path) | |
lines.each do|line| | |
#puts "I read this line: #{line.chomp}" | |
url = line.chomp | |
http = EventMachine::HttpRequest.new(url).get #.get( :timeout => 10) | |
http.callback { | |
http.response_header.status | |
puts url | |
pp http.response_header | |
#p http.response | |
filename = Digest::MD5.hexdigest(http.uri.to_s) | |
File.open('./data/'+ filename, 'w') { |f| f.write(http.response) } | |
pp filename | |
#else | |
# puts "#{http.inspect} failed" | |
#end | |
} | |
end | |
end | |
def file_moved | |
puts "#{path} moved" | |
end | |
def file_deleted | |
puts "#{path} deleted" | |
end | |
def unbind | |
puts "#{path} monitoring ceased" | |
end | |
end | |
EventMachine.kqueue=true | |
EventMachine.run { | |
EventMachine.watch_file($urlfile, Handler) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment