Module: Twtail

Defined in:
lib/twtail.rb

Class Method Summary collapse

Class Method Details

.execute(params = nil) ⇒ Object



14
15
16
17
# File 'lib/twtail.rb', line 14

def self.execute(params=nil)
  trap("INT") { exit }
  params ? self.search(params) : self.help
end

.helpObject



19
20
21
# File 'lib/twtail.rb', line 19

def self.help
  return("Usage: twtail [xbox+live | from:caffo | '#barcamp']")
end

.search(params) ⇒ Object



23
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
# File 'lib/twtail.rb', line 23

def self.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")
            puts "\033[32m#{item.author.sub(/(\w+).+\n.+/,'\1')}: \033[0m\033[37m#{coder.decode(item.title)}\033[0m"
            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(10)
    end
  rescue
     "No data was found for this criteria. please try with other keywords."
  end
end