DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Emad has posted 58 posts at DZone. View Full User Profile

Printing twitter and github followers

06.26.2014
| 1118 views |
  • submit to reddit
#!/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'