Created
February 22, 2021 20:32
-
-
Save royeradames/2b5327dd41cfa0a7c6362925cb3f065c to your computer and use it in GitHub Desktop.
custom file loader reports
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//custom file loader reports | |
// design for downloading 1 complete file at a time | |
let intervalID | |
page.on('download', async download => { | |
startDownloadReport(download, intervalID) | |
// last report | |
download.saveAs(`./data/${ download.suggestedFilename()}`).then(() => { | |
endDownloadReport(download, intervalID) | |
}) | |
}); | |
function endDownloadReport(download, intervalID){ | |
clearInterval(intervalID) | |
console.log(`Time ${Date().split(" ")[4]}: Finished ${download.suggestedFilename()} file download. `) | |
} | |
function startDownloadReport(download, intervalID) { | |
// initial file report | |
console.log(`Time ${Date().split(" ")[4]}: Starting ${download.suggestedFilename()} file download. `) | |
// continues waiting reports | |
intervalID = setInterval( () => { | |
console.log(`Time ${Date().split(" ")[4]}: File is still downloading. `) | |
}, 30000) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment