task.js
1.27 KB
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
const _ = require('lodash')
const spider = require('./libs/spider')
const report = require('./libs/report')
const sknsData = require('./data/skns.json')
const sizeRelation = require('./data/size.json')
const logger = global.logger
module.exports = async () => {
spider(sknsData.map(p => p.productId))
.forEach(promise => promise.then(result => {
if (result.status !== 200 && !_.has(result, 'data.detail')) {
logger.warn(`爬取失败记录:${JSON.stringify(result)}`)
return
}
const {data: {detail, sizeList}} = result
const yhProduct = sknsData.find(p => p.productId === detail.productId)
sizeList.forEach(s => {
const find = sizeRelation[s.size]
if (!find) {
return logger.error(`爬取尺码对应关系未找到: ${JSON.stringify(s)}`)
}
if (_.isPlainObject(s.item) && s.item.price > 0) {
logger.info(JSON.stringify({
productId: yhProduct.yhId,
sizeId: find.sizeId,
price: s.item.price / 100,
time: Date.now()
}))
// report({
// productId: yhProduct.yhId,
// sizeId: find.sizeId,
// price: s.item.price / 100,
// time: Date.now()
// })
}
})
}))
}