Sha256: 03c92b1a17d5cca41f691204a54c439b434426aab7a7116bd1054742e8a92eec

Contents?: true

Size: 1.27 KB

Versions: 4

Compression:

Stored size: 1.27 KB

Contents

module Chatterbot

  #
  # handle Twitter searches
  module Search

    MAX_SEARCH_TWEETS = 1000
    
    @skip_retweets = true
    
    #
    # modify a query string to exclude retweets from searches
    #
    def exclude_retweets
      @skip_retweets = true
    end

    def include_retweets
      @skip_retweets = false
    end

    def skippable_retweet?(t)
      @skip_retweets && t.retweeted_status?
    end
    
    # internal search code
    def search(queries, opts = {}, &block)
      debug "check for tweets since #{since_id}"

      max_tweets = opts.delete(:limit) || MAX_SEARCH_TWEETS
      
      if queries.is_a?(String)
        queries = [queries]
      end

      #
      # search twitter
      #
      queries.each { |query|
        debug "search: #{query} #{default_opts.merge(opts)}"
        @current_tweet = nil
        client.search( query, default_opts.merge(opts) ).take(max_tweets).each { |s|
          update_since_id(s)
          debug s.text
          if has_whitelist? && !on_whitelist?(s)
            debug "skipping because user not on whitelist"
          elsif block_given? && !on_blacklist?(s) && !skip_me?(s) && !skippable_retweet?(s)
            @current_tweet = s
            yield s
          end
        }
        @current_tweet = nil
      }
    end
  
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
chatterbot-1.0.2 lib/chatterbot/search.rb
chatterbot-1.0.1 lib/chatterbot/search.rb
chatterbot-1.0.0 lib/chatterbot/search.rb
chatterbot-0.9.3 lib/chatterbot/search.rb