-
Notifications
You must be signed in to change notification settings - Fork 14
/
grab12306.js
37 lines (32 loc) · 1003 Bytes
/
grab12306.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
var fs = require('fs');
var path = require('path');
var Promise = require('bluebird');
var moment = require('moment');
var config = require('./config.js');
var util = require('./lib/util.js');
var grabStation = require('./lib/grab_station.js');
var grabTrain = require('./lib/grab_train.js');
var grabSchedule = require('./lib/grab_schedule.js');
var logger = require('winston');
logger.remove(logger.transports.Console);
logger.add(logger.transports.Console, {
colorize: true
});
logger.add(logger.transports.File, {
filename: 'grab12306.log'
});
var beginTime = moment();
var global = {};
global.config = config;
//车站
grabStation(global).then(function() {
//车次
return grabTrain(global);
}).then(function() {
//时刻表
return grabSchedule(global);
}).then(function() {
const seconds = moment().unix() - beginTime.unix();
var time = moment().startOf('day').seconds(seconds);
logger.info("所有抓取已完成,共耗时"+time.format("H时mm分ss秒"));
}).catch(logger.error);