Last active
December 28, 2015 08:39
-
-
Save johndel/7473591 to your computer and use it in GitHub Desktop.
Fql first attempt: Find TV shows with genre comedy through facebook pages.
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 'koala' | |
require 'rubygems' | |
require 'active_record' | |
ActiveRecord::Base.establish_connection( | |
:adapter => 'mysql2', | |
:database => 'test', | |
:username => 'whatever', | |
:password => 'whatever', | |
:host => 'localhost') | |
class Movie < ActiveRecord::Base | |
end | |
File.open("en-US.dic", "r").each_line do |line| | |
puts line | |
@api = Koala::Facebook::API.new("CAACEdEose0cBAHctpQ7HHVya0mzZBYymq67uMh4NVh0ckZCjQXeaQMIvbTqOYgQvqTa4OuhliV9WmCVsuaNZB0i9Lghg6q3iXZChsQK1H67w1gpQDEWn0BeMvJZBTEZAkJrFt9oZAoZAoEaaJ0xW7M906hHWOLpqRGdIe9g4SepmudgwWwlsLJDLn8HXTV9Y2j0ZD") | |
results = @api.fql_query("select page_id, name, genre, fan_count, type from page WHERE CONTAINS('#{line}') AND type='TV SHOW' AND genre='comedy'") | |
results.each do |result| | |
unless Movie.where(page_id: result["page_id"]).first | |
movie = Movie.new | |
movie.keyword = line | |
movie.page_id = result["page_id"] | |
movie.name = result["name"] | |
movie.genre = result["genre"] | |
movie.fan_count = result["fan_count"] | |
movie.category = result["type"] | |
movie.save rescue puts "Problem with: #{result['page_id']}" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment