Created
February 11, 2011 10:31
-
-
Save n0ts/822184 to your computer and use it in GitHub Desktop.
Tweets #qpstudy
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
--- | |
2011-02-11 19:28:00 | |
Total tweets: 1485 | |
Gentoo: 202 | |
Ubuntu: 124 | |
Debian: 119 | |
Vine: 79 | |
Fedora: 65 | |
--- | |
require "rubygems" | |
require "twitter" | |
$KCODE = 'u' | |
require "moji" | |
# result | |
result = { | |
:Gentoo => 0, | |
:Fedora => 0, | |
:Debian => 0, | |
:Ubuntu => 0, | |
:Vine => 0, | |
} | |
puts DateTime.now.strftime("%Y-%m-%d %H:%M:%S") | |
# Initialize a Twitter search | |
search = Twitter::Search.new | |
# search 15 tweet per page | |
count = 0 | |
loop do | |
begin | |
search.containing("#qpstudy").fetch | |
break unless search.next_page? | |
tweets = search.fetch_next_page | |
next if tweets.nil? | |
tweets.each do |r| | |
count += 1 | |
case Moji.zen_to_han(r.text) | |
when /(Gentoo|gentoo)/ | |
#puts "Gentoo #{r.text}" | |
result[:Gentoo] += 1 | |
when /(RHEL|Fedora|fedora)/ | |
#puts "Fedora #{r.text}" | |
result[:Fedora] += 1 | |
when /(Debian|debian)/ | |
#puts "Debian #{r.text}" | |
result[:Debian] += 1 | |
when /(Ubuntu|ubuntu)/ | |
#puts "Ubuntu #{r.text}" | |
result[:Ubuntu] += 1 | |
when /(Vine|vine)/ | |
#puts "Vine #{r.text}" | |
result[:Vine] += 1 | |
end | |
end | |
rescue | |
# ignore | |
end | |
end | |
# clear | |
search.clear | |
# show result | |
puts "Total tweets: #{count}" | |
result.sort{|a, b| | |
b[1] <=> a[1] | |
}.each do |k, v| | |
puts "#{k}:\t#{v}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment