Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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