Skip to content

Instantly share code, notes, and snippets.

@rounak
Created January 18, 2013 07:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rounak/4562912 to your computer and use it in GitHub Desktop.
Save rounak/4562912 to your computer and use it in GitHub Desktop.
Script writes to STDOUT the Twitter clients you've used along with the number of tweets. Save the output as something.csv and open in Excel/Numbers to do interesting things like making charts etc.
#redirect stdout to something.csv and open it in Numbers/Excel to do whatever you want
require 'csv'
#total_tweets = 0
client_hash = {}
dir_name = "~/path/to/tweetsfolder/" + "data/csv/" #insert path to tweets folder
file_paths_array = Dir.entries(dir_name)
file_paths_array.delete_at(0)
file_paths_array.delete_at(0)
file_paths_array.each do |file_path|
arr_of_arrs = CSV.read(dir_name+file_path)
arr_of_arrs.delete_at(0)
arr_of_arrs.each do |arr|
client_name = arr[6].gsub(%r{<[^>]*>},"")
#total_tweets = total_tweets+1
client_hash[client_name] = client_hash[client_name].to_i() + 1
end
end
#puts total_tweets
client_hash.each do |key,value|
puts key + "," + value.to_s
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment