24
25
26
27
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
60
61
62
63
|
# File 'lib/twtail.rb', line 24
def search(params)
begin
pointer = Time.now-86400
parameter = CGI::escape(params)
url = "http://search.twitter.com/search.atom?q=#{parameter}"
feed = SimpleRSS.parse open(url)
coder = HTMLEntities.new
puts "\033[37m==\033[0m \033[1;32m#{feed.channel.title}\033[0m \033[37m==\033[0m\n\n" unless Module.constants.include?("DEBUG")
if feed.items[0].published < pointer
puts "No items found since yesterday"
exit
end
while 1==1 do
new_items = false
begin
feed = SimpleRSS.parse open(url) rescue nil
feed.items.each do |item|
next if item.published < pointer
unless Module.constants.include?("DEBUG")
msg = colorize(37, coder.decode(item.title))
msg = colorize(31, msg, /(#[[\d]]?(\S+))/i)
msg = colorize(33, msg, /(@[[\d]]?(\S+))/i)
msg = colorize(34, msg, /(https?:\/\/[\S]+)/i)
puts "#{coder.decode(from_parser(item.author))} #{msg}"
new_items = true
end
end
rescue
end
puts "\n\n" if new_items == true
pointer = feed.items[0].published + 1
break if Module.constants.include?("DEBUG")
sleep(60)
end
rescue
"No data was found for this criteria. please try with other keywords."
end
end
|