require "open-uri.rb"
require "net/smtp"
recipients = ['tarzan@rabbit.com','dew@rabbit.com']
logfile = 'log.rby.txt'
pageurl = 'http://fruit.alsacreations.fr/'
f = open(pageurl)
re = Regexp.compile('
(.*?)')
title = false
if f
for ligne in f.readlines
m = re.match(ligne)
if m
if m[1].length>0
title = m[1]
end
end
end
f.close
end
if title
puts "Title : "+title
begin
f = open(logfile)
if f
last_title = f.read(1024)
f.close
end
rescue
last_title = false
end
if last_title!=title
puts "Différence !\n"
msg = ["Subject: [Turborabbit] New title\n","\n","(Script Ruby) New title !\n"+title+"\n" ]
Net::SMTP.start('localhost') do |smtp|
for recipient in recipients
sm = smtp.sendmail(msg,'dumbo@jumbo.com',recipient)
if sm[0,3]=="250"
puts "Mail to "+recipient
end
end
end
begin
f = open(logfile,'w')
if f
f.write(title)
end
rescue
puts "Cannot write to file"
end
end
end