Last active
August 29, 2015 14:11
-
-
Save alexcameron89/1ffd58de9abbbe23497c to your computer and use it in GitHub Desktop.
Cleaning fake fans from a Facebook Page.
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
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 |
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
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