-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
119 lines (111 loc) · 3.56 KB
/
app.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
const express = require('express');
const curl = require('curl');
const account = require('./account');
const app = express();
/**
* 启动服务:http://localhost:3000
*/
console.log('|———————————————————————————————|');
console.log('| |');
console.log('| 服务器启动中 |');
app.listen(3000, function () {
console.log('| 服务器启动成功 |');
console.log('| http://localhost:3000 |');
console.log('| |');
console.log('|———————————————————————————————|');
});
// 所有数值
const allData = [];
const addItem = (item) => allData.find(data => data.id === item.id) ? void 0 : allData.push(item);
// 聚丰开放平台--有赞批发网
const getJFYouZan = () => new Promise((resolve, reject) => {
curl.get(
account.JFYouZan.url, {
headers: {
cookie: account.JFYouZan.cookie
}
},
(err, res, data) => {
if (err) {
console.log(err);
reject(err);
}
const startIndex = data.lastIndexOf('data: {');
const endIndex = data.lastIndexOf('},');
const _data = data.slice(startIndex + 5, endIndex + 1);
const reg = /\[(\S+)\]/g;
// 下载日期
const strDay = reg.exec(_data)[1];
const days = strDay.split(',');
// 下载数量
const strNum = reg.exec(_data)[1];
const num = strNum.split(',');
const down = [];
days.forEach((item, index) => {
down.push({
[item.match(/\d{4}-\d{2}-\d{2}/)[0]]: ~~(num[index].match(/\d+/)[0]),
})
})
const yz = {
id: 1,
name: '聚丰开放平台--有赞批发网',
downloads: down
}
addItem(yz);
resolve(yz);
}
);
});
// 百度移动开放平台--零售开店宝
const getBDLingShou = () => new Promise((resolve, reject) => {
curl.get(
account.BDLingShou.url, {
headers: {
cookie: account.BDLingShou.cookie
}
},
(err, res, data) => {
if(err) {
console.log(err);
reject(err);
}
data = JSON.parse(data);
if(!data.success) {
console.log(data.result);
reject(data.result);
}
const result = data.result;
const daily = result.daily;
const down = [];
Object.keys(daily).forEach(item => down.push({
[item]: daily[item]['零售开店宝']
}));
const ls = {
id: 2,
name: '百度移动开放平台--零售开店宝',
downloads: down
}
addItem(ls);
resolve(ls);
}
)
})
/**
* Api
*/
// 百度移动开放平台--零售开店宝
app.get('/jfyouzan', (req, res) => {
getJFYouZan().then(data => res.send(data));
});
// 百度移动开放平台--零售开店宝
app.get('/bdlingshou', (req, res) => {
getBDLingShou().then(data => res.send(data));
});
// allData
const promiseList = [
getJFYouZan(),
getBDLingShou(),
];
app.get('/', (req, res) => {
Promise.all(promiseList).then(data => res.send(allData)).catch(err => res.send(err));
} )