-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy path04_galleryVIewGrep.js
101 lines (86 loc) · 2.82 KB
/
04_galleryVIewGrep.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/**
* Created by ecst_000 on 2016-01-09.
*/
var async = require('async');
var fs = require('fs');
var cheerio = require('cheerio');
var config = require('./core/config');
var articleId = [];
async.waterfall([
// get list
function (callback) {
console.log('get galleries list');
fs.readdir('./result/', callback);
},
function (list, callback) {
var queue = [];
for (var i in list) {
var entry = list[i];
if ('gallery_list' === entry.substr(0, 12)) {
queue.push(entry);
}
}
callback(null, queue);
},
function (queue, callback) {
async.eachSeries(
queue,
function (filename, next) {
async.waterfall([
function (subroutine) {
fs.readFile('./result/' + filename, 'utf8', subroutine);
},
function (data) {
articleId = articleId.concat(JSON.parse(data));
next();
}
]);
},
function () {
console.log('galleries done');
callback();
}
);
},
// get auth
function (callback) {
console.log('get auth');
require('./core/auth')(config.userId, config.password, config.rsaPublic, config.rsaModulus,
callback);
},
// paring cookie
function (cookies, callback) {
console.log('paring cookies');
var cookieLength = cookies.length;
var newCookie = [];
for (var i = 0; i < cookieLength; i++) {
var chuck = cookies[i];
newCookie.push(chuck.substring(0, chuck.indexOf('; ')));
}
callback(null, newCookie.join('; '));
},
function (cookies) {
async.eachSeries(
articleId,
function (articleNo, next) {
async.waterfall([
function (subroutine) {
console.log('download article - ' + articleNo);
require('./core/galleryView')(cookies, config.clubId, articleNo, subroutine);
},
function (cookies, articleNo, data, subroutine) {
console.log('parsing article - ' + articleNo);
require('./core/parseGalleryView')(cookies, articleNo, data, subroutine);
},
function (cookies, articleNo, contents) {
fs.writeFile('result/gallery_view_' + articleNo + '.txt', JSON.stringify(contents));
setTimeout(next, 1000);
}
]);
},
function () {
console.log('galleries done');
}
);
}
]);