Last active
April 2, 2017 14:41
-
-
Save SarahTaylorProject/6b6cfa21345b0b5dae3cd8a14d5742d3 to your computer and use it in GitHub Desktop.
This movie code API test is working but still needs a bit of work for splitting up directors and so forth March 31st 2017
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 "csv" | |
require "json" | |
movie_titles = CSV.read("movies.csv").map { |row| | |
row[1] | |
}.uniq | |
movie_results = movie_titles.first(10).map { |movie_title| | |
print(".") | |
[movie_title, JSON.parse(`curl "http://www.omdbapi.com/?t=#{movie_title.gsub(/\s/,"+")}"`)] | |
} | |
rowid = 0 | |
CSV.open("movie_results.csv", 'w') do |csv| | |
csv << ["RowID", "Movie_Title_Input", "Movie_Title_Match", "Director", "Writer", "imdbID"] | |
movie_results.each do |movie_title, movie_data| | |
rowid += 1 | |
csv << [rowid, movie_title, movie_data["Title"], movie_data["Director"], movie_data["Writer"], movie_data["imdbID"]] | |
end# of rows | |
end# of csv open |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment