Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'rubygems'
- require 'nokogiri'
- require 'rest-client'
- require 'mail'
- require 'uri'
- 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 get_url
- url = RestClient.get('https://vk.com/psychohell')
- end
- def read_html(link)
- page = Nokogiri::HTML(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
- begin
- execution_loop(60) do
- url = get_url
- html_page = read_html(url)
- status = get_status(html_page)
- send_email(status)
- end
- rescue
- LoadError
- ensure
- puts "Попробуйте еще раз"
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement