Skip to content

Instantly share code, notes, and snippets.

@veryhappythings
Created July 30, 2009 17:03
Show Gist options
  • Save veryhappythings/158780 to your computer and use it in GitHub Desktop.
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.
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