Skip to content

Instantly share code, notes, and snippets.

@yosmoc
Created May 23, 2011 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yosmoc/986734 to your computer and use it in GitHub Desktop.
Save yosmoc/986734 to your computer and use it in GitHub Desktop.
#!/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