Created
July 12, 2012 07:23
-
-
Save paulvictor/3096442 to your computer and use it in GitHub Desktop.
Tv shows from FB
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
#!/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