<?xml version="1.0" encoding="UTF-8"?>
<plugin-url>
  <approved type="boolean">true</approved>
  <author>Highgroove Studios</author>
  <cached-tag-list>yahoo, popularity</cached-tag-list>
  <canonical-name nil="true"></canonical-name>
  <code>class YahooTotalEntries &lt; Scout::Plugin
  
  TEST_USAGE = &quot;#{File.basename($0)} terms TERMS&quot;
  
  def require_libs
    require 'net/http'
    require 'hpricot'
    require 'cgi'
  end
  
  def run
    begin
      require_libs
    rescue LoadError
      begin
        require &quot;rubygems&quot;       
        require_libs
      rescue LoadError
        return { :error =&gt; { :subject =&gt; &quot;Couldn't load required libraries.&quot;,
                             :body    =&gt; &quot;Please see the required libaries in the README file&quot; } }
      end
    end
    
    # The following attributes are required:
    # - term
    if [@options[&quot;terms&quot;]].map { |opt| opt.strip.length}.find { |v| v.zero? }
      return { :error =&gt; { :subject =&gt; &quot;A search term must be provided.&quot; } }
    end
    
    # grabs data from the current day
    data = get_data(@options[&quot;terms&quot;])
    { :report =&gt; data }
  rescue
    { :error =&gt; {:subject =&gt; &quot;Yahoo! data could not be collected&quot;,
                 :body    =&gt; &quot;#{$!.message}\n\n#{$!.backtrace}&quot;}
    }
  end # run
  
  private
  
  # Returns a 2-element hash with the circulation and feed hits
  def get_data(terms)
    # don't think a unique id is required
    app_id = &quot;unique_app_id&quot;
    
    terms = terms.split(',')
    results = {}
    
    terms.each do |t|
      query = CGI::escape(t)
      url =&quot;http://api.search.yahoo.com/WebSearchService/V1/webSearch?appid=#{app_id}&amp;query=#{query}&quot;
      res = Net::HTTP.get_response(URI.parse(url))
      doc = Hpricot(res.body)
      
      total = doc.at(&quot;resultset&quot;)['totalresultsavailable']
      
      results[t.gsub(&quot;\&quot;&quot;,'').strip] = total
      
    end # terms.each
    
    results
  end
    
end # Feedburner
</code>
  <created-at type="datetime">2007-12-29T12:39:02-08:00</created-at>
  <default-triggers type="yaml" nil="true"></default-triggers>
  <description>Returns the total number of entries for each of the provided search terms. Separate multiple terms with a &quot;,&quot;. 

For example, to return the total number of entries for each of these two terms:&lt;br/&gt;

- Bill Clinton
- George Bush&lt;br/&gt;

Specify this as the term: &quot;Bill Clinton&quot;, &quot;George Bush&quot;

Which return 2 fields in the report:&lt;br/&gt;

Bill Clinton: 854,554,545
George Bush: 765,345,434&lt;br/&gt;

If you want all results that match those terms:&lt;br/&gt;

Term: &quot;Bill Clinton&quot; OR &quot;George Bush&quot;

Total Entries: 854,554,545 + 765,345,434&lt;br/&gt;

Code (and inspiration) taken and updated from:

http://kfahlgren.com/blog/2005/12/10/why-does-the-google-search-api-suck/
&lt;br/&gt;
*Dependencies*

Requires the following libraries:

require 'net/http'
require 'hpricot'
require 'cgi'
</description>
  <featured type="boolean">false</featured>
  <id type="integer">8</id>
  <metadata type="yaml">--- |+
options:
  terms:
    name: Term(s)
    notes: The terms to search for. Separate multiple terms with a comma.

</metadata>
  <name>Yahoo Total Entries</name>
  <plugins-count type="integer">1</plugins-count>
  <rating-avg type="decimal" nil="true"></rating-avg>
  <rating-count type="integer" nil="true"></rating-count>
  <rating-total type="integer" nil="true"></rating-total>
  <readme>Yahoo! Total Entries Count Plugin
=================================
Created by [Highgroove Studios LLC](http://www.highgroove.com)

Returns the total number of entries for each of the provided search terms. Separate multiple terms with a &quot;,&quot;. 

Dependencies
------------
Requires the [hpricot library](http://code.whytheluckystiff.net/hpricot/):

	sudo gem install hpricot
	
Usage Notes
-----------

To return the total number of entries for each of these two terms:

* Bill Clinton
* George Bush

Specify this as the term: &quot;Bill Clinton&quot;, &quot;George Bush&quot;

Which return 2 fields in the report:

* Bill Clinton: 854,554,545
* George Bush: 765,345,434

If you want all results that match those terms:

Term: &quot;Bill Clinton&quot; OR &quot;George Bush&quot;

Total Entries: 854,554,545 + 765,345,434

Code (and inspiration) taken and updated from:

http://kfahlgren.com/blog/2005/12/10/why-does-the-google-search-api-suck/

Compatibility 
-------------

Works on Linux and OSX. 

</readme>
  <schema type="yaml" nil="true"></schema>
  <scout-version type="integer">1</scout-version>
  <short-description>Returns the total number of entries for each of the provided search terms. Separate multiple terms with a &quot;,&quot;. </short-description>
  <tested-platforms>linux macox</tested-platforms>
  <total-usage-count type="integer">0</total-usage-count>
  <updated-at type="datetime">2009-09-23T23:03:09-07:00</updated-at>
  <url>http://github.com/highgroove/scout-plugins/raw/7d13f07023d2d284fefceca078a86718e928f4d0/yahoo_total_entries/yahoo_total_entries.rb</url>
</plugin-url>
