-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
50 lines (45 loc) · 1.61 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
var fs = require('fs'),Î
crawler = require('./crawler');
var env = process.env.NODE_ENV = process.env.NODE_ENV || 'development';
var config = require('./config')[env];
var checkMovies = function() {
if(moviesToParse.length > 0) {
var movieId = moviesToParse.shift();
var movieUrl = "http://www.imdb.com/title/"+movieId+"/";
crawler.readMovie(movieUrl, movieId).then(function(movie) {
fs.appendFile('files/movies.data', JSON.stringify(movie) + "\n", function() { m++; console.log("m", m); });
for (var j = 0; j < movie.cast.length; j++) {
var castMember = movie.cast[j];
actorsToParse.push(castMember.imdbid);
}
checkActors();
}).catch(function(err) {
console.log('fail', err);
});
}
};
var checkActors = function() {
if(actorsToParse.length > 0) {
var actorId = actorsToParse.shift();
var actorUrl = "http://www.imdb.com/name/"+actorId+"/";
crawler.readActor(actorUrl, actorId).then(function(actor) {
fs.appendFile('files/actors.data', JSON.stringify(actor) + "\n", function() { a++; console.log("a", a); });
for (var j = 0; j < actor.movies.length; j++) {
var movie = actor.movies[j];
moviesToParse.push(movie.imdbid);
}
checkMovies();
}).catch(function(err) {
console.log('actor fail', err);
});
}
};
var moviesToParse = ['tt0111161'];
var actorsToParse = [];
var m = 0;
var a = 0;
var i = 0;
while(i++ < 100) {
checkMovies();
checkActors();
}