Skip to content

Instantly share code, notes, and snippets.

@bcjordan
Created October 17, 2011 20:06
Show Gist options
  • Save bcjordan/1293640 to your computer and use it in GitHub Desktop.
Save bcjordan/1293640 to your computer and use it in GitHub Desktop.
Identifies some Netflix Instant movies in a Reddit thread
require 'rubygems'
require 'open-uri'
require 'pp'
require 'nokogiri'
PAGE_URL = "http://www.reddit.com/r/AskReddit/comments/lf38m/what_is_the_funniest_movie_you_have_ever_seen/"
page_text = Nokogiri::HTML(open(PAGE_URL))
page_text.css('div.usertext-body').each do |content|
comments = content.content.split("\n")
comments.each do |comment|
movie = nil
begin
movie = comment.split("\n").first.gsub(/[^a-zA-Z ]/, '').gsub(' ', '%20')
rescue
end
if movie && movie.split(' ').length < 6
result = open("http://odata.netflix.com/Catalog/Titles?$filter=Name%20eq%20%27#{movie}%27&amp;$format=json").read
puts "Trying... #{movie}"
if result.include?'<d:Available m:type="Edm.Boolean">true</d:Available>'
puts "Instant: #{movie}"
end
sleep 0.5
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment