42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
# File 'lib/WMATA_Alerts/wmata_alerts.rb', line 42
def run(params)
die if params[0] == "-h"
@cutoff_string = params[0] || "7 days ago"
@width = params[1] || "40"
@width = @width.to_s.to_i
@cutoff = Chronic.parse(@cutoff_string)
@rss_content = ""
open(FEED_URL) do |f|
@rss_content = f.read
end
@rss = RSS::Parser.parse(@rss_content, false)
@item_hash = {}
@rss.items.each do |item|
@item_hash[item.pubDate] = item unless item.pubDate < @cutoff
end
if @item_hash.empty?
puts "No data from WMATA feed."
else
@coder = HTMLEntities.new
@item_hash.keys.sort.reverse.each do |key|
item = @item_hash[key]
title = "#{item.pubDate.strftime('%x')} - #{item.title}"
puts title
puts ("-" * title.length)
message = @coder.decode(item.description)
REPLACEMENTS.each do |r|
message = message.gsub(r[0], r[1])
end
subject, *body = message.split(".")
puts Utility.wrap_text(subject+"...", @width)
body.each do |sentence|
puts Utility.wrap_text(sentence+".", @width, 3, :all)
end
puts
end
end
end
|