Sha256: 414bc8503abcbef824225fbfd966c58ec94e1d8bb6ea9822ab7d8b81014e78ea

Contents?: true

Size: 1.08 KB

Versions: 1

Compression:

Stored size: 1.08 KB

Contents

module StreamBot
  # The Tracker class that provides a start and a stop method 
  class Tracker
    # the initialization method aka the constructor
    def initialize(auth, blacklist, *keywords)
      LOG.debug("#{self.class}#initialize")
      @stream = TweetStream::Client.new(auth[:username],auth[:password])
      # initializing retweet
      @retweet = StreamBot::Retweet.new(auth) #
      # get string with keywords comma separated keywords 
      @keywords=keywords.join(',')
      # set blacklist array if not nil
      @blacklist=blacklist
    end
    
    # start the bot
    def start
      LOG.debug("#{self.class}#start")
      # starting to track the keywords via tweetstream
      @stream.track(@keywords) do |status|
        username = status.user.screen_name
        # if status.user is NOT in blacklist then retweet it
        if !@blacklist.include?(username)
          LOG.debug("#{self.class}#start - retweet ##{status.id} from @#{username}")
          @retweet.retweet(status.id)
        end
      end  
    end  
    
    # stop the bot
    def stop
      @stream.stop
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
streambot-0.3.0 lib/streambot/tracker.rb