#!/usr/bin/ruby ########################################################################### ## Copyright (C) Wizardry and Steamworks 2016 - License: GNU GPLv3 ## ## Please see: http://www.gnu.org/licenses/gpl.html for legal details, ## ## rights of fair usage, the disclaimer and warranty conditions. ## ########################################################################### ########################################################################### # CONFIGURATION # ########################################################################### ACCESS_TOKEN="CBANDsD5FkXweAwyvutwqnjbE4nfZBBkfXUCvNHLBZAURZCKqYuXu54ZB46fhtUupaou3lG0xUYIcik9DMPbSJpyeGbOFGNLjleoJy1kiNIrtwcKyjrj0xmZAQTMR5vZCKvRUjYL8Y9lirIVVdUOBe6QhFRNyAp4QWqZC18IlaUEDXmwczXYhcK1" ########################################################################### # INTERNALS # ########################################################################### require "koala" require "json" # Get the friends list through Koala. @graph = Koala::Facebook::API.new(ACCESS_TOKEN) friends = @graph.get_connections( "me", "invitable_friends", { limit: 5000 } ) # Read the friends stored in the script. store = Array.new mark = false File.open(File.expand_path(__FILE__), "r") do | s | s.each_line do | line | if line.start_with? "# FACEBOOK FRIENDS LIST" mark = true next end if mark store.push line.split('#').last.strip end end end store = store.sort # Get the new list of friends. fetch = Array.new friends.each do | f | fetch.push f["name"] end fetch = fetch.sort # Check for friends that are no longer friends. store.each do | f | if !fetch.include? f puts f + " " + "is no longer your friend." end end # Check for newly added friends. fetch.each do | f | if !store.include? f puts f + " " + "is a new friend." end end # Read the entire script up to the friends marker script = Array.new File.open(File.expand_path(__FILE__), "r") do | s | s.each_line do | line | if line.start_with? "# FACEBOOK FRIENDS LIST" break; end script.push line end end # Write the script back to the file File.open(File.expand_path(__FILE__), "w") do |s| script.each do | line | s.write line end # And append the new friends s.write "# FACEBOOK FRIENDS LIST" + "\n" fetch.each do |f | s.write "#" + " " + f + "\n" end end puts "You have a total of: " + fetch.length.to_s + " friends." ### Here we store the previous list of friends # FACEBOOK FRIENDS LIST