28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/OPM_Alerts/opm_alerts.rb', line 28
def run(params)
die if params[0] == "-h"
width = (params[1] and params[1].to_i) || 40
doc = Nokogiri::HTML(open(URL))
date_str = doc.css('#_ctl0__ctl0_DisplayDateSpan').text.strip
begin
date = Date.parse(date_str)
date_str = date.strftime("%x")
rescue
date_str = Date.today.strftime("%x") if date_str.length == 0
end
title = doc.css('h3').text.strip
title = "VRE Status" if title.length == 0
status = doc.css('.statusbox').text.strip
images = doc.xpath("//img")
status = images[0].attributes["alt"].text.strip if ((status.length == 0) && (images.count == 1))
status = "Not found" if status.length == 0
puts Utility.wrap_text("#{date_str} - #{title}", width, date_str.length + 3, :outdent)
puts "-" * width
puts Utility.wrap_text(status, width)
end
|