-
Number of tweets (excluding RTs): 359
-
Number of tweeting users: 107
| Rank | User | Tweets |
|---|---|---|
1. |
33 |
|
2. |
25 |
|
3. |
23 |
|
4. |
14 |
|
5. |
12 |
|
6. |
11 |
|
7. |
9 |
|
8. |
9 |
|
9. |
8 |
|
10. |
8 |
|
11. |
8 |
Number of tweets (excluding RTs): 359
Number of tweeting users: 107
| Rank | User | Tweets |
|---|---|---|
1. |
33 |
|
2. |
25 |
|
3. |
23 |
|
4. |
14 |
|
5. |
12 |
|
6. |
11 |
|
7. |
9 |
|
8. |
9 |
|
9. |
8 |
|
10. |
8 |
|
11. |
8 |
| #!/usr/bin/env ruby | |
| # | |
| # Quick & dirty script to count some Twitter statistics of #LinuxDays 2014. | |
| # | |
| # Usage: | |
| # 1. gem install twitter | |
| # 2. Register your “app” on https://apps.twitter.com/apps and set OAuth | |
| # credentials here. | |
| # 3. Profit! | |
| # | |
| # License: | |
| # Creative Commons CC-Zero This file is made available under the Creative | |
| # Commons CC0 1.0 Universal Public Domain Dedication. | |
| # https://creativecommons.org/publicdomain/zero/1.0/deed.en | |
| # | |
| require 'twitter' | |
| HASHTAG = '#LinuxDays' | |
| DATE_FROM = '2014-10-04' | |
| DATE_TO = '2014-10-06' | |
| YEAR = DATE_FROM.split('-').first | |
| client = Twitter::REST::Client.new do |config| | |
| config.consumer_key = 'YOUR_CONSUMER_KEY' | |
| config.consumer_secret = 'YOUR_CONSUMER_SECRET' | |
| config.access_token = 'YOUR_ACCESS_TOKEN' | |
| config.access_token_secret = 'YOUR_ACCESS_SECRET' | |
| end | |
| def title(level, text) | |
| mark = '=' * (level + 1) | |
| puts "\n#{mark} #{text}\n\n" | |
| end | |
| def table(headers, data, &block) | |
| lines = ['|===', '| ' + headers.join(' | '), ''] | |
| data.each_with_index do |item, idx| | |
| cols = yield item, idx + 1 | |
| lines << '| ' + cols.join(' | ') | |
| end | |
| lines << '|===' << '' | |
| puts lines.join("\n") | |
| end | |
| tweets = client.search("#{HASHTAG} since:#{DATE_FROM} until:#{DATE_TO}", result_type: :all) | |
| .reject { |tweet| tweet.retweet? } | |
| title 1, "Twitter statistics for #{HASHTAG} #{YEAR}" | |
| top_users = tweets.inject(Hash.new(0)) { |memo, tweet| | |
| memo[tweet.user] += 1; memo | |
| }.sort_by(&:last).reverse! | |
| puts "* Number of tweets (excluding RTs): #{tweets.count}" | |
| puts "* Number of tweeting users: #{top_users.count}" | |
| title 2, 'TOP tweeting users' | |
| table %w(Rank User Tweets), top_users.select { |_, tweets| tweets > 7 } do |(user, tweets), idx| | |
| ["#{idx}.", "#{user.uri}[@#{user.screen_name}]", tweets] | |
| end | |
| title 2, 'TOP favourited tweets' | |
| top_favourites = tweets.sort_by(&:favorite_count).reverse.select do |tweet| | |
| tweet.favorite_count > 4 | |
| end | |
| table %w(Rank Tweet Favourites), top_favourites do |tweet, idx| | |
| ["#{idx}.", "#{tweet.uri}[#{tweet.text}]", tweet.favorite_count] | |
| end | |
| title 2, 'TOP retweeted tweets' | |
| top_retweets = tweets.sort_by(&:retweet_count).reverse.select do |tweet| | |
| tweet.retweet_count > 2 | |
| end | |
| table %w(Rank Tweet Retweets), top_retweets do |tweet, idx| | |
| ["#{idx}.", "#{tweet.uri}[#{tweet.text}]", tweet.retweet_count] | |
| end |