Skip to content

Instantly share code, notes, and snippets.

@jboursiquot
Created November 22, 2013 22:55
Show Gist options
  • Save jboursiquot/7608291 to your computer and use it in GitHub Desktop.
Save jboursiquot/7608291 to your computer and use it in GitHub Desktop.
require 'json'
require 'pry'
require 'csv'
require 'open-uri'
def parse_movie_data(data)
JSON.parse(data)
end
def populate_csv(movies, filename)
CSV.open(filename, "w") do |csv|
csv << ["Title", "Released", "Pop", "Avg", "Count"]
movies.each do |movie|
csv << [movie["title"], movie["release_date"], movie["popularity"], movie["vote_average"], movie["vote_count"]]
end
end
end
data_from_the_internets = open("http://api.themoviedb.org/3/movie/upcoming?api_key=ae1df922d4a3023ff2eb92784e9e82ac&page=2")
movies = parse_movie_data(data_from_the_internets.read)["results"]
populate_csv movies, ARGV.last
puts "done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment