Skip to content

Instantly share code, notes, and snippets.

@paulvictor
Created July 12, 2012 07:23
Show Gist options
  • Save paulvictor/3096442 to your computer and use it in GitHub Desktop.
Save paulvictor/3096442 to your computer and use it in GitHub Desktop.
Tv shows from FB
#!/usr/bin/env ruby
require 'csv'
require 'rest-client'
require 'json'
CSV.foreach("./tv_shows.csv") do |row|
begin
name = row[1]
row[1].gsub!(/ /, "+")
puts("https://graph.facebook.com/search?until=yesterday&q=#{row[1]}&type=page")
resp = RestClient.get("https://graph.facebook.com/search?until=yesterday&q=#{row[1]}&type=page&fields=name,category,likes")
vals = JSON.parse(resp)['data']
vals.select!{|val| val['category'] == "Tv show"}
with_most_likes = vals.inject{|memo, val| memo['likes'] > val['likes'] ? memo : val}
puts with_most_likes.inspect
puts "#{name} : www.facebook.com/#{with_most_likes['id']}"
rescue Exception
puts "couldn't get for #{name}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment