-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgetFromBd.js
47 lines (40 loc) · 1.24 KB
/
getFromBd.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
import config from './config.js';
import https from 'https';
let query = {
newmap: 1,
reqflag: "pcmap",
biz: 1,
from: "webmap",
da_par: "direct",
qt: "fav",
mode: "get",
type: "favdata",
limit: config.baiduLimit,
lastver: 0,
}
let getUrl = "https://ditu.baidu.com/?" + Object.entries(query).map(v => v.join("=")).join("&");
export default async function getFromBd() {
return new Promise(rs => {
https.get(getUrl, {
headers: {
Cookie: config.baidu
}
}, (resp) => {
let data = '';
// A chunk of data has been received.
resp.on('data', (chunk) => {
data += chunk;
});
// The whole response has been received. Print out the result.
resp.on('end', () => {
let list = JSON.parse(data).sync.newdata.filter(v => v.detail?.data?.sourcedata);
rs(list.map(v => ({
name: v.detail.data.extdata.name,
city: v.detail.data.tags && v.detail.data.tags.find(v => v.type == 2)?.name
})))
});
}).on("error", (err) => {
console.log("Error: " + err.message);
});
})
}