Advertisement
Guest User

Untitled

a guest
Dec 4th, 2017
353
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.38 KB | None | 0 0
  1. require 'rubygems'
  2. require 'nokogiri'
  3. require 'rest-client'
  4. require 'mail'
  5.  
  6. options = { :address              => "smtp.gmail.com",
  7.             :port                 => 587,
  8.             :domain               => 'localhost',
  9.             :user_name            => 'pavel.shebalkou@gmail.com',
  10.             :password             => '********',
  11.             :authentication       => 'plain',
  12.             :enable_starttls_auto => true }
  13.  
  14. Mail.defaults do
  15.   delivery_method :smtp, options
  16. end
  17.  
  18. def execution_loop(period)
  19.   loop do
  20.     before = Time.now
  21.     yield
  22.     interval = period - (Time.now - before)
  23.     sleep(interval) if interval > 0
  24.   end
  25. end
  26.  
  27. def read_html(link)
  28.   page = Nokogiri::HTML(RestClient.get(link))
  29. end
  30.  
  31. def get_status(page)
  32.   status = page.css('.profile_time_lv').text
  33. end
  34.  
  35. def send_email(status)
  36.   if status.include?("заходил") || status.include?("сети")
  37.     puts "Вадим #{status}"
  38.  
  39.   else
  40.     Mail.deliver do
  41.       to 'elizeoban@gmail.com'
  42.       from 'pavel.shebalkou@gmail.com'
  43.       subject 'vk_online_checker_notification'
  44.       body 'Nell is now online'
  45.     end
  46.     puts 'Вадим сейчас Online'
  47.   end
  48. end
  49.  
  50. #puts 'Введите ссылку на пользователя'
  51. link = "https://vk.com/psychohell"
  52.  
  53.  
  54. execution_loop(60) do
  55.   html_page = read_html(link)
  56.   status = get_status(html_page)
  57.   send_email(status)
  58. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement