Last Updated: February 25, 2016
·
1.052K
· blazeeboy

Printing twitter and github followers

this script could be part of large script of monitoring your followers number across social media, and sum them to form a social score of some kind just like klout does.
as i didn't find an apropriate api to get these data as guest i had to scrap the data from html pages using regex.
if there are other social media that we can add to this script i'll be more than happy if you forked this script and modified.

Gist : https://github.com/blazeeboy/RubyScripts/tree/master/2014-5-13

#!/usr/bin/env ruby
# Author : Emad Elsaid (https://github.com/blazeeboy)
# 
# this script will get your followers count
# across socsial media, i get the user profile
# page and use Regex to grab the followers number
require 'open-uri'

# Getting github followers
def github( username )
  page = open("https://github.com/#{username}").read
  followers = page.scan(/<.+>([0-9]+)<.+>[[:space:]]+followers/i).flatten.first
  puts "Github : #{followers} Followers"
end

# get twitter followers by twitter handle
def twitter( username )
  page = open("https://twitter.com/#{username}").read
  followers = page.scan(/followers<.+>[[:space:]]+<.+>([0-9]+)<.+>/i).flatten.first
  puts "Twitter : #{followers} Followers"
end

# use them to print your followers
# using github username and
# twitter handle
github 'blazeeboy'
twitter 'blaz_boy'

1 Response
Add your response

I like it! made it into a file and let the person specify whoever they want:

#!/usr/bin/env ruby
# Author : Emad Elsaid (https://github.com/blazeeboy)
# 
# this script will get your followers count
# across socsial media, i get the user profile
# page and use Regex to grab the followers number
require 'open-uri'

# Getting github followers
def github( username )
  page = open("https://github.com/#{username}").read
  followers = page.scan(/<.+>([0-9]+)<.+>[[:space:]]+followers/i).flatten.first
  puts "Github : #{followers} Followers"
end

# get twitter followers by twitter handle
def twitter( username )
  page = open("https://twitter.com/#{username}").read
  followers = page.scan(/followers<.+>[[:space:]]+<.+>([0-9]+)<.+>/i).flatten.first
  puts "Twitter : #{followers} Followers"
end

# use them to print your followers
# using github username and
# twitter handle

if ARGV.count == 2
  github ARGV.first
  twitter ARGV.last
elsif ARGV.include? "--help"
  puts "Usage: ruby filename github_handle twitter_handle"

else
  puts "unrecognized option, Try '--help' for more information."
end
over 1 year ago ·