Skip to content

Instantly share code, notes, and snippets.

@alexcameron89
Last active August 29, 2015 14:11
Show Gist options
  • Save alexcameron89/1ffd58de9abbbe23497c to your computer and use it in GitHub Desktop.
Save alexcameron89/1ffd58de9abbbe23497c to your computer and use it in GitHub Desktop.
Cleaning fake fans from a Facebook Page.
require 'sqlite3'
require 'fb_graph'
db = SQLite3::Database.new("#{ENV['HOME']}/clientdb.db")
db.execute <<-SQL
create table fans (
username varchar(30),
name varchar(30),
location varchar(30),
to_delete boolean
);
SQL
puts 'Database Created'
fans = File.open('PATH_TO_YOUR_FANS_FILE', 'r').read.split("\n")
fans.each do |fan|
begin
name, username = fan.split('|')
person = FbGraph::User.fetch(username)
db.execute("INSERT INTO fans (username, name, location)
VALUES (?, ?, ?)", [username, name, person.locale])
puts "#{name} Added"
rescue Exception => e
puts e.message
next
end
end
require 'sqlite3'
db = SQLite3::Database.open("#{ENV['HOME']}/clientdb.db")
keep_array = ['en_US', 'fr_CA'] #fill this in with the locales to keep
delete_array = ['fa_IR', 'pt_BR'] #fill this in with ones to delete
keep_array.each do |locale|
db.execute("UPDATE fans SET to_delete='FALSE' WHERE location=#{locale};")
end
delete_array.each do |locale|
db.execute("UPDATE fans SET to_delete='TRUE' WHERE location=#{locale};")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment