Last active
December 10, 2015 05:29
-
-
Save Haar/4388449 to your computer and use it in GitHub Desktop.
Grabs the first result of an IMDB query for a title passed in as the first argument on the command line and saves the image and basic description for the film.
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 'curb' | |
require 'json' | |
require 'fileutils' | |
include FileUtils | |
film_title = ARGV[0] | |
request = Curl::Easy.new("http://imdbapi.org/?title=#{film_title}&type=json&plot=simple&episode=1&limit=1&yg=0&mt=none&lang=en-US&offset=&aka=simple&release=simple") | |
request.perform | |
films = JSON(request.body_str) | |
film = films.first | |
mkdir_p film_title | |
cd film_title | |
file = File.open("text.txt", "w") do |file| | |
file.puts(film["title"]) | |
file.puts(film["plot_simple"]) | |
file.puts(film["genres"]) | |
end | |
Curl::Easy.download(film["poster"]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Reorganised so that if the query blows then an empty folder isn't created.