-
-
Save macdiva/2849360 to your computer and use it in GitHub Desktop.
Calculate the percentage of tweets linking to a website that came from the Tweet button
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Before running: | |
# $ gem install twitter | |
# | |
# To run: | |
# $ ruby counter.rb sleazywebsite.com | |
# | |
# Context: | |
# http://luigimontanez.com/2012/actually-social-media-buttons-work-really-well | |
# | |
require 'rubygems' | |
require 'twitter' | |
search_term = ARGV[0] | |
total_tweets = 0 | |
from_button = 0 | |
pages = 5 | |
(1..pages).each do |page| | |
Twitter.search(search_term, :rpp => 100, :page => page).each do |tweet| | |
total_tweets += 1 | |
from_button += 1 if tweet.source =~ /Tweet Button/ | |
end | |
end | |
percentage = (from_button.to_f / total_tweets.to_f) * 100 | |
puts "Search term: #{search_term}" | |
puts "Total tweets analyzed: #{total_tweets}" | |
puts "Tweets from button: #{from_button} (#{sprintf('%.1f', percentage)}%)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment