Skip to content

Instantly share code, notes, and snippets.

@ppolischuk
Forked from luigi/counter.rb
Created June 3, 2012 16:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ppolischuk/2864135 to your computer and use it in GitHub Desktop.
Save ppolischuk/2864135 to your computer and use it in GitHub Desktop.
Calculate the percentage of tweets linking to a website that came from the Tweet button
#
# Before running:
# $ gem install twitter
#
# To run:
# $ ruby counter.rb plosone.org
#
# 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: #{dx.plos.org}"
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