Skip to content

Instantly share code, notes, and snippets.

@jirutka
Created October 13, 2015 00:11
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 jirutka/61ef5573ff1e8634a1a4 to your computer and use it in GitHub Desktop.
Save jirutka/61ef5573ff1e8634a1a4 to your computer and use it in GitHub Desktop.
Twitter statistics for #LinuxDays 2015

Twitter statistics for #LinuxDays 2015

  • Number of tweets (excluding RTs): 323

  • Number of favourites: 718

  • Number of retweets: 239

  • Number of tweeting users: 134

TOP tweeting users

TOP favourited tweets

Rank Tweet(s) Favourites

1.

@LinuxDaysCZ: Dnes bylo na #LinuxDays celkem 790 lidí. My organizátoři jsme nadšení a děkujeme! Je to odměna za naše snažení. Těšíme se na zítřek.

21

2.

@Rootcz: „Proč by mělo být HTTPS všude? Protože to psali na Rootu!“ @tomashala na #LinuxDays

15

3.

@PetrHodac: Po @FIT_CTU se uz prohaneji prvni tucnaci na @LinuxDaysCZ #cvut #linux #linuxdays http://t.co/EJYl6P4LK8

@krcmar: „Pokud se hlásíte na server pomocí SSH a něco tam děláte, tak to děláte špatně!“ Věroš Kaplan v přednášce o orchestraci na #LinuxDays

@kofarna_cz: #LinuxDays je za námi. Děkujeme organizátorům za pozvání na super akci..ostatním přítomným za přízeň..tak za rok.. http://t.co/5EqsozoAPn

13

4.

@krcmar: Vyrážím na #LinuxDays do Prahy. Zítra se tam potkáme! http://t.co/xXy6cwGhxM

@krcmar: Jen Chuck Norris může testovat v produkčním prostředí. Vy to nedělejte a použijte Vagrant! #LinuxDays http://t.co/K8zFRTiXRa

12

5.

@krcmar: „Příště to budete dělat v O2 Aréně,“ řekl mi jeden člověk na #LinuxDays. Asi budeme muset, protože to je velké. Ale proto to děláme!

@vit_kabele: Když přednáší @flash_sh, pokaždé žasnete, že vám shell dosud fungoval #linuxdays

@LinuxDaysCZ: #Linuxdays jsou za nami ale uz ted se muzete tesit na @SUT_SH @OpenAlt @InstallFest_SH a @CryptoFest_SH

11

6.

@PetrHodac: Vstavat! #LinuxDays

@JiriFolta: Prijdte na @RedHatJobs + @FedoraCZ stánky na #LinuxDays http://t.co/g5d2YS6Kne

@LinuxDaysCZ: Nemůžete dorazit na #LinuxDays ? Pusťte si alespoň streamy z webu: https://t.co/548aMVQaqn

9

TOP retweeted tweets

Rank Tweet(s) Retweets

1.

@LinuxDaysCZ: Nemůžete dorazit na #LinuxDays ? Pusťte si alespoň streamy z webu: https://t.co/548aMVQaqn

15

2.

@krcmar: „Pokud se hlásíte na server pomocí SSH a něco tam děláte, tak to děláte špatně!“ Věroš Kaplan v přednášce o orchestraci na #LinuxDays

9

3.

@krcmar: Jen Chuck Norris může testovat v produkčním prostředí. Vy to nedělejte a použijte Vagrant! #LinuxDays http://t.co/K8zFRTiXRa

8

4.

@JiriFolta: packing for #Prague #LinuxDays see you tomorrow and Sunday at the @RedHatJobs table! http://t.co/5CXV1hmKw5

@kofarna_cz: #LinuxDays je za námi. Děkujeme organizátorům za pozvání na super akci..ostatním přítomným za přízeň..tak za rok.. http://t.co/5EqsozoAPn

6

5.

@LinuxDaysCZ: Aktualizovali jsme odkazy na nedělní streamy na #LinuxDays . Začínáme za deset minut! https://t.co/548aMVQaqn

@gretel_mejia: @_MauroMorales of @SUSE presenting #Machinery at #LinuxDays Prague 2015 http://t.co/H1j8BOH4Rq

@LinuxDaysCZ: #Linuxdays jsou za nami ale uz ted se muzete tesit na @SUT_SH @OpenAlt @InstallFest_SH a @CryptoFest_SH

5

6.

@kofarna_cz: příprava na #LinuxDays proběhla…​zítra se na vás těšíme http://t.co/QXufXaqhdQ

@Rootcz: „Proč by mělo být HTTPS všude? Protože to psali na Rootu!“ @tomashala na #LinuxDays

@vit_kabele: Když přednáší @flash_sh, pokaždé žasnete, že vám shell dosud fungoval #linuxdays

@LinuxDaysCZ: Dnes bylo na #LinuxDays celkem 790 lidí. My organizátoři jsme nadšení a děkujeme! Je to odměna za naše snažení. Těšíme se na zítřek.

@PetrHodac: S @ttknet sedime na super prednasce o #kubernetes od @tomkukral z @FIT_CTU na #linuxdays http://t.co/20jAvhhJaO

@horcicaa: Kalkulačka zapojená podle @adent na stánku @bastlirna #LinuxDays http://t.co/SmHQSikkJs

4


Generated on 2015-10-13 02:07:28 +0200.

#!/usr/bin/env ruby
#
# Quick & dirty script to generate some Twitter statistics for events.
#
# 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 'ostruct'
require 'twitter'
######## Configuration ########
HASHTAG = '#LinuxDays'
DATE_FROM = '2015-10-09'
DATE_TO = '2015-10-12'
USERS_LIST_LIMIT = 10
FAVORITES_LIST_LIMIT = 6
RETWEETS_LIST_LIMIT = 6
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
year = DATE_FROM.split('-').first
######## Functions ########
def top_tweets_by(field, tweets)
tweets.lazy
.group_by { |tw| tw.public_send(field) }
.sort.reverse
.map { |count, tweets| [count, tweets.sort_by(&:created_at)] }
end
def top_users_by_tweets_count(tweets)
tweets.lazy
.group_by(&:user)
.map { |user, tweets| [user, tweets.count] }
.group_by(&:last) # group by number of tweets
.sort.reverse
.map { |count, tuples| [count, tuples.map(&:first)] } # extract users as value of the entry
.map { |count, users| [count, users.sort_by(&:screen_name)] }
end
def title(level, text)
puts "\n\n#{'=' * level} #{text}\n\n"
end
def table(headers, data, &block)
lines = ['|===', '| ' + headers.join(' | '), '']
data.each_with_index do |item, idx|
(yield item, idx + 1).each do |col|
lines << "| #{col}"
end
lines << ''
end
lines << '|===' << ''
puts lines.join("\n")
end
format_user = ->(user) { "#{user.uri}[@#{user.screen_name}] (#{user.followers_count})" }
format_tweet = ->(tweet) { "@#{tweet.user.screen_name}: #{tweet.uri}[#{tweet.text}]" }
######## Main ########
tweets = client.search("#{HASHTAG} since:#{DATE_FROM} until:#{DATE_TO}", result_type: :all)
.reject { |tweet| tweet.retweet? }
users = tweets.map(&:user).uniq
favourites_count = tweets.map(&:favorite_count).reduce(:+)
retweets_count = tweets.map(&:retweet_count).reduce(:+)
top_users = top_users_by_tweets_count(tweets).take(USERS_LIST_LIMIT)
top_favorites = top_tweets_by(:favorite_count, tweets).take(FAVORITES_LIST_LIMIT)
top_retweets = top_tweets_by(:retweet_count, tweets).take(RETWEETS_LIST_LIMIT)
# Print report in AsciiDoc
title 1, "Twitter statistics for #{HASHTAG} #{year}"
puts "* Number of tweets (excluding RTs): #{tweets.count}"
puts "* Number of favourites: #{favourites_count}"
puts "* Number of retweets: #{retweets_count}"
puts "* Number of tweeting users: #{users.count}"
title 2, 'TOP tweeting users'
puts "List of most active users sorted by number of their tweets with hashtag #{HASHTAG}.\n\n"
table ['Rank', 'User(s)', 'Tweets'], top_users do |(count, users), idx|
["#{idx}.", users.map(&format_user).join(', '), count]
end
title 2, 'TOP favourited tweets'
table ['Rank', 'Tweet(s)', 'Favourites'], top_favorites do |(count, tweets), idx|
["#{idx}.", tweets.map(&format_tweet).join("\n\n"), count]
end
title 2, 'TOP retweeted tweets'
table ['Rank', 'Tweet(s)', 'Retweets'], top_retweets do |(count, tweets), idx|
["#{idx}.", tweets.map(&format_tweet).join("\n\n"), count]
end
puts "\n\n''''"
puts "_Generated on #{Time.now}._"
@profi248
Copy link

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment