Skip to content

Instantly share code, notes, and snippets.

@sathia27
Created October 31, 2013 10:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sathia27/7247311 to your computer and use it in GitHub Desktop.
Save sathia27/7247311 to your computer and use it in GitHub Desktop.
Get movies imdb rating for movies in given directory
require 'net/http'
require 'open-uri'
require 'nokogiri'
class Imdb
def initialize movies
@movies = movies
end
def results
@movies.each do |movie|
begin
url = 'https://www.google.co.in/search?q='+movie
encoded_url = URI.encode(url.strip)
uri = URI.parse(encoded_url)
Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
request = Net::HTTP::Get.new encoded_url
response = http.request request # Net::HTTPResponse object
puts movie + ": " + Nokogiri::HTML(response.body).at_css("div.star").parent.text if Nokogiri::HTML(response.body).at_css("div.star")
end
rescue => e
puts e
end
end
end
end
Dir.chdir(ARGV[0])
folders = Dir.entries(Dir.pwd)
Imdb.new(folders).results
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment