Skip to content

Instantly share code, notes, and snippets.

@bcjordan
Created October 17, 2011 20:27
Show Gist options
  • Save bcjordan/1293695 to your computer and use it in GitHub Desktop.
Save bcjordan/1293695 to your computer and use it in GitHub Desktop.
Uses InstantWatcher to find possible instant movies
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/"
INSTANT_WATCHER = "http://instantwatcher.com/titles?q=QUERY&search_episodes=0"
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-Z0-9 ]/, '').gsub(' ', '+')
rescue
end
if movie && movie.split(' ').length < 6
result = open(INSTANT_WATCHER.gsub('QUERY', movie)).read
puts "Instant: #{movie}" if !result.include? "No results."
sleep 0.5
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment