Created
April 6, 2015 03:48
-
-
Save domitry/1cf11c47f3e334c58b45 to your computer and use it in GitHub Desktop.
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
#! ruby | |
require "twitter" | |
require "json" | |
CONSUMER_KEY = "" | |
CONSUMER_SECRET = "" | |
ACCESS_TOKEN = "" | |
ACCESS_SECRET = "" | |
STR_BLACK = "\033[30m" | |
FILL_RED = "\033[41m" | |
FILL_GREEN = "\033[42m" | |
RESET = "\033[0m" | |
LOG_PATH = "/home/domitry/twirem.json" | |
SCREEN_NAME = "domitry" | |
def print_red(str); print STR_BLACK, FILL_RED, str, RESET; end | |
def print_green(str); print STR_BLACK, FILL_GREEN, str, RESET; end | |
client = Twitter::REST::Client.new do |config| | |
config.consumer_key = CONSUMER_KEY | |
config.consumer_secret = CONSUMER_SECRET | |
config.access_token = ACCESS_TOKEN | |
config.access_token_secret = ACCESS_SECRET | |
end | |
prev_followers = open(LOG_PATH){|f| JSON.parse(f.map{|l| l}.join)} | |
now_followers = client.follower_ids.map{|id| id} | |
removed_ids = prev_followers.reduce([]){|memo, id| (now_followers.index(id).nil? ? memo + [id] : memo)} | |
new_ids = now_followers.reduce([]){|memo, id| (prev_followers.index(id).nil? ? memo + [id] : memo)} | |
if removed_ids.length != 0 | |
client.users(removed_ids).each do |user| | |
print_red "- @" + user.screen_name + "\n" | |
end | |
end | |
if new_ids.length != 0 | |
client.users(new_ids).each do |user| | |
print_green "+ @" + user.screen_name + "\n" | |
end | |
end | |
print "Follower num: " + now_followers.length.to_s | |
str = JSON.generate(now_followers) | |
File.write(LOG_PATH, str) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment