Skip to content

Instantly share code, notes, and snippets.

@royeradames
Created February 22, 2021 20:32
Show Gist options
  • Save royeradames/2b5327dd41cfa0a7c6362925cb3f065c to your computer and use it in GitHub Desktop.
Save royeradames/2b5327dd41cfa0a7c6362925cb3f065c to your computer and use it in GitHub Desktop.
custom file loader reports
//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