From 862981141bdb8ac6de5026fdfbdf2ed501e16ebd Mon Sep 17 00:00:00 2001 From: DeadmanM Date: Thu, 6 Oct 2016 18:39:08 -0400 Subject: [PATCH 1/2] Movie parser script --- movie_parser.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100755 movie_parser.rb diff --git a/movie_parser.rb b/movie_parser.rb new file mode 100755 index 0000000..bc36bf3 --- /dev/null +++ b/movie_parser.rb @@ -0,0 +1,19 @@ +#!/usr/bin/ruby +require 'json' +require 'open-uri' + +# Will open ip the imdb api and return the title and year of our first result +def callAPI(name) + unless name.nil? + # I chose to use the title_popular option over the title_exact option since + # we don't know the full title and over the title_substring since it seemed + # to return videos related to our search term instead of movies + json = JSON.parse(open("http://www.imdb.com/xml/find?json=1&nr=1&tt=on&q=#{name}") { |x| x.read }) + # Should do more date validation but I will assume it's always the first 4 characters + "Title: " + json["title_popular"][0]["title"] + "\nYear: " + json["title_popular"][0]["title_description"][0..3] + else + "No movie title specified" + end +end + +puts callAPI(ARGV[0]) From f91c1965aa1f1b4a0f514fe2c64cd53b352c99ba Mon Sep 17 00:00:00 2001 From: DeadmanM Date: Thu, 6 Oct 2016 18:52:43 -0400 Subject: [PATCH 2/2] No movie found bug fix --- movie_parser.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/movie_parser.rb b/movie_parser.rb index bc36bf3..8f8f5c0 100755 --- a/movie_parser.rb +++ b/movie_parser.rb @@ -10,9 +10,10 @@ def callAPI(name) # to return videos related to our search term instead of movies json = JSON.parse(open("http://www.imdb.com/xml/find?json=1&nr=1&tt=on&q=#{name}") { |x| x.read }) # Should do more date validation but I will assume it's always the first 4 characters - "Title: " + json["title_popular"][0]["title"] + "\nYear: " + json["title_popular"][0]["title_description"][0..3] + return "Title: " + json["title_popular"][0]["title"] + "\nYear: " + json["title_popular"][0]["title_description"][0..3] unless json["title_popular"].nil? + "No movie with the specified title" else - "No movie title specified" + "Please specify a movie title" end end