download-h5data.js
893 Bytes
const open = require("open");
const dayjs = require('dayjs');
const shelljs = require('shelljs')
const start = dayjs('2018-12-28 11:00:00');
const end = dayjs(dayjs().format('YYYY-MM-DD HH:00:00'));
const files = shelljs.ls('./other/files')
const download = (hour) => {
const startTime = start.add(hour, 'hour');
const endTime = start.add(hour + 1, 'hour');
if (endTime.diff(end, 'hour') > 0) {
return;
}
const url = `https://h5data.yoho.cn/rs/ufo/prod/size/download?startTime=${startTime.format('YYYYMMDD-HH')}&endTime=${endTime.format('YYYYMMDD-HH')}`;
const file = `${startTime.format('YYYYMMDD-HH')}_${endTime.format('YYYYMMDD-HH')}.xls`
if (!files.some(f => f === file)) {
console.log(file, url)
open(url)
return setTimeout(() => {
download(hour + 1);
}, 1000);
}
setTimeout(() => {
download(hour + 1);
}, 1);
}
download(0)