カスペルスキーのサイトからウィルスレベルをスクレイピングして、つぶやく。

  • 3
    Like
  • 0
    Comment
More than 1 year has passed since last update.

Gem::Tiwtter、Gem::Mechanize必須。

kaspersky.rb
#! /usr/bin/ruby -Ku

#require 'kconv'
#require 'oauth'
require 'rubygems'
require 'mechanize'
require 'twitter'
require 'date'

date = Time.now.strftime("%H:%M:%S").to_s

agent = Mechanize::new
agent.user_agent_alias = "Windows IE 9"

agent.get('http://www.securelist.com/en/')  
agent.page.encoding = "EUC-JP"

activity = agent.page.search('span.m').to_s
activity = activity.scan(/Internet threat level:../)

threat_level = activity[0].split(' ')

case threat_level[3]
when "1"
 message = "[Threat level 1] The Internet threat alert status is currently normal."
when "2"
 message = "[Threat level 2] The Internet threat alert status is currently raised."
when "3"
 message = "[Threat level 3] The Internet threat alert status is currently high."
when "4"
 message = "[Threat level 4] The Internet threat alert status is currently critical.(http://www.securelist.com/en/)"
else
 message = "kaspersky_bot is busy..."
end

oauth = Twitter::OAuth.new('consumer token', 'consumer secret')
oauth.authorize_from_access('access token', 'access secret')

client = Twitter::Base.new(oauth)
client.update(date + message)