'selecting a random movie from imdb csv file
I have a very large IMDB CSV file (9500 lines) (if you're not familiar with IMDB CSV files here's a sample), and I want to pick a random movie with its information.
The reason I want to do this is that I'm coding a node.js program that will need a random movie title, rating.....etc.
I tried to use imdb module but its results are really poor and the module isn't working well and it doesn't seem there's an alternative to it so I thought why not using a CSV file as an API or something idk. is this possible? importing a CSV file as an array and pick a random movie from it? please tell me anything you might know to help me. Thanks!
Solution 1:[1]
I can recommend a module to deal with CSVs which works very efficiently and can process large CSV files without issue - http://papaparse.com/
Here is a rough example for how you could use the module
var my_array = Papa.parse(csvFile, { header: true });
// Now pick a random movie
var random_movie = my_array[Math.floor(Math.random()*my_array.length)]
// We turned headers on, so we can access the name like this:
console.log(random_move["Title"]);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Matt |
