Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pre-interview submission #44

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions movie_parser.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/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
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
"Please specify a movie title"
end
end

puts callAPI(ARGV[0])