Created
May 23, 2011 13:58
-
-
Save yosmoc/986734 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# -*- coding: utf-8 -*- | |
require 'mechanize' | |
require 'kconv' | |
require 'ruby-growl' | |
PATH="http://www.kurashi-no-techo.co.jp/" | |
class Kurashi_no_hinto | |
def initialize | |
@agent = Mechanize.new | |
@agent.user_agent_alias = 'Mac Safari' | |
@hinto = [] | |
end | |
attr_reader :hinto | |
def collect | |
push_item(get) | |
return get | |
end | |
def load(file_name) | |
if FileTest.exist?(file_name) | |
File.open(file_name, 'r') do |file| | |
while item = file.gets | |
@hinto << item.chomp | |
end | |
end | |
else | |
return nil | |
end | |
end | |
def dump(file_name) | |
File.open(file_name, 'w') do |file| | |
@hinto.each do |item| | |
file.puts item | |
end | |
end | |
end | |
def growl | |
item = collect | |
g = Growl.new('localhost', 'ruby-growl', ['ruby-growl Notification']) | |
g.notify('ruby-growl Notification', '暮らしのヒント集', item) | |
end | |
def get | |
@agent.get(PATH) | |
return @agent.page.at("dl[@class='hint']/dd/p").inner_text | |
end | |
private | |
def push_item(item) | |
unless @hinto.include?(item) | |
@hinto << item | |
end | |
end | |
end | |
if __FILE__ == $0 | |
kh = Kurashi_no_hinto.new | |
kh.load('./kurashi_no_hinto.txt') | |
kh.growl | |
kh.dump('./kurashi_no_hinto.txt') | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment