Created
October 31, 2013 10:12
-
-
Save sathia27/7247311 to your computer and use it in GitHub Desktop.
Get movies imdb rating for movies in given directory
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 '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