-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtransformData.js
53 lines (50 loc) · 1.79 KB
/
transformData.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
import request from 'request';
import config from './config.js';
export default function transformData(keywords) {
return new Promise(rs => {
let options = {
'method': 'GET',
'url': 'https://www.amap.com/service/poiInfo?query_type=TQUERY&keywords=' + keywords,
'headers': {
'Cookie': config.amap,
'Referer': 'https://www.amap.com/',
'x-csrf-token': config.amapToken
}
};
request(options, function (error, response) {
if (error) throw new Error(error);
let d = JSON.parse(response.body);
if (!d.data || !d.data.poi_list) {
console.log("query by keywords fail");
rs(0);
return;
}
let pos = d.data.poi_list[0];
let options2 = {
'method': 'GET',
'url': 'https://www.amap.com/detail/get/detail?id=' + pos.id,
'headers': {
'Cookie': config.amap,
'Referer': 'https://www.amap.com/',
'x-csrf-token': config.amapToken
}
};
request(options2, function (error, response) {
if (error) throw new Error(error);
let d = JSON.parse(response.body);
if (!d.data) {
console.log("get detail fail:" + response.body);
rs(0);
return;
}
let data = {
name: d.data.base.name,
address: d.data.base.address,
point_x: d.data.base.pixelx,
point_y: d.data.base.pixely
}
rs(data);
});
});
})
}