Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'rubygems'
- require 'nokogiri'
- require 'rest-client'
- require 'mail'
- options = { :address => "smtp.gmail.com",
- :port => 587,
- :domain => 'localhost',
- :user_name => 'pavel.shebalkou@gmail.com',
- :password => '********',
- :authentication => 'plain',
- :enable_starttls_auto => true }
- Mail.defaults do
- delivery_method :smtp, options
- end
- def execution_loop(period)
- loop do
- before = Time.now
- yield
- interval = period - (Time.now - before)
- sleep(interval) if interval > 0
- end
- end
- def read_html(link)
- page = Nokogiri::HTML(RestClient.get(link))
- end
- def get_status(page)
- status = page.css('.profile_time_lv').text
- end
- def send_email(status)
- if status.include?("заходил") || status.include?("сети")
- puts "Вадим #{status}"
- else
- Mail.deliver do
- to 'elizeoban@gmail.com'
- from 'pavel.shebalkou@gmail.com'
- subject 'vk_online_checker_notification'
- body 'Nell is now online'
- end
- puts 'Вадим сейчас Online'
- end
- end
- #puts 'Введите ссылку на пользователя'
- link = "https://vk.com/psychohell"
- execution_loop(60) do
- html_page = read_html(link)
- status = get_status(html_page)
- send_email(status)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement