Class: TodayInHistory

Inherits:
Object
  • Object
show all
Includes:
Features
Defined in:
lib/feature/TodayInHistory.rb

Instance Method Summary collapse

Methods included from Features

included

Constructor Details

#initialize(opts = {:url => "http://www1.wst.net.cn/scripts/flex/TodayOnHistory/",:log => Logger.new(File.join(File.dirname(__FILE__),'..','..','log','wish_mailer.log'))}) ⇒ TodayInHistory

Returns a new instance of TodayInHistory.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/feature/TodayInHistory.rb', line 4

def initialize(opts = {:url => "http://www1.wst.net.cn/scripts/flex/TodayOnHistory/",:log => Logger.new(File.join(File.dirname(__FILE__),'..','..','log','wish_mailer.log'))})
  require "open-uri"
  require "iconv"
  require 'hpricot'

  @log = opts[:log] || Logger.new(File.join(File.dirname(__FILE__),'..','..','log','wish_mailer.log'))

  begin
    @log.info "Get TodayInHistroy...Patient"
    page = open(opts[:url])
    content = page.readlines.join($/)

    @doc = Hpricot(Iconv.conv('utf-8','GBK', content))
    # @doc = Hpricot(page)
  rescue => e
    @log.error e.to_s
  end

end

Instance Method Details

#fdataObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/feature/TodayInHistory.rb', line 24

def fdata
  begin
    r = []
    r << "Today In Histroy"
    r << "<br/>"*2
    r << "<ol>"
    
    # :url => "http://www.todayonhistory.com/"
    # (@doc/'//div[@id=d4]/li').search("a").each{|x| r << x.inner_text}
    # A faster page:
    # :url => "http://www1.wst.net.cn/scripts/flex/TodayOnHistory/"
    (@doc/'//td[@class=a]').search("a").each{|x| r << "<li>#{x.inner_text}</li>"}

    r << "</ol>"
    r.join($/) + "<br/>"*4
  rescue => e
    @log.error e.to_s
    nil
  end
end