-
Notifications
You must be signed in to change notification settings - Fork 0
/
fetchTrafficData.js
29 lines (27 loc) · 1.09 KB
/
fetchTrafficData.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
const downloadFile = (content, fileName, contentType) => {
var a = document.createElement("a");
var file = new Blob([content], {
type: contentType
});
a.href = URL.createObjectURL(file);
a.download = fileName;
a.click();
}
const getTraffic = async (subwayInfo) => {
let lineIndex = 0;
let stationIndex = 0;
let timer = setInterval(async () => {
subwayInfo.l[lineIndex].st[stationIndex].officeBuilding = await getIndex(subwayInfo.l[lineIndex].st[stationIndex].sl, '商务写字楼');
subwayInfo.l[lineIndex].st[stationIndex].residential = await getIndex(subwayInfo.l[lineIndex].st[stationIndex].sl, '住宅小区');
stationIndex++;
if (stationIndex >= subwayInfo.l[lineIndex].st.length) {
stationIndex = 0;
lineIndex++;
if (lineIndex >= subwayInfo.l.length) {
downloadFile(JSON.stringify(subwayInfo), `${subwayInfo.i}.json`, 'application/json; charset=utf-8');
document.querySelector('.fetch-data').innerHTML = `Data fetched and saved, please paste the file into data folder`;
clearInterval(timer);
}
}
}, 1000);
}