Skip to content

Instantly share code, notes, and snippets.

@Haar
Last active December 10, 2015 05:29
Show Gist options
  • Save Haar/4388449 to your computer and use it in GitHub Desktop.
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.
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"])
@Haar
Copy link
Author

Haar commented Dec 27, 2012

Reorganised so that if the query blows then an empty folder isn't created.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment