Created
July 30, 2009 17:03
-
-
Save veryhappythings/158780 to your computer and use it in GitHub Desktop.
A little script for a friends project - scans the twitterverse and tells you how everyone's feeling today.
This file contains 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
require 'rubygems' | |
require 'twitter' | |
HEALTHII_TAG_REGEX = /#healthii\((\d{4}):?(.*)?\)/ | |
BUSYNESS, STRESS, HEALTH, ENGAGEMENT = 0, 1, 2, 3 | |
def mean(numbers) | |
numbers.inject {|sum, n| sum + n } / numbers.length.to_f | |
end | |
Stats = (0..3).map { [] } | |
Users = [] | |
Twitter::Search.new('healthii').each do |result| | |
next if Users.include? result.from_user | |
Users << result.from_user | |
if match = HEALTHII_TAG_REGEX.match(result.text) | |
match[1].split(//).each_index do |i| | |
Stats[i] << match[1][i,1].to_i | |
end | |
end | |
end | |
puts 'The Healthii twitterverse currently feels a bit like this:' | |
puts "Busyness: #{mean(Stats[BUSYNESS])}" | |
puts "Stress: #{mean(Stats[STRESS])}" | |
puts "Health: #{mean(Stats[HEALTH])}" | |
puts "Engagement: #{mean(Stats[ENGAGEMENT])}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment