diff --git a/tools/download-stats.js b/tools/download-stats.js index 5925a5f1..86f0e037 100644 --- a/tools/download-stats.js +++ b/tools/download-stats.js @@ -33,6 +33,21 @@ This page was automatically generated on ${formattedDate}. fs.writeFileSync(markdownFile, markdownContent); } +async function deleteExistingAttachments() { + try { + const files = fs.readdirSync(attachmentDestination); + + for (const file of files) { + if (path.extname(file) === '.png') { + fs.unlinkSync(path.join(attachmentDestination, file)); + console.log(`Deleted ${file}`); + } + } + } catch (error) { + console.error(error); + } +} + const config = getEnvVars(['EMAIL', 'EMAIL_APP_PASSWORD']); const imap = new Imap({ @@ -111,6 +126,8 @@ imap.once('ready', async () => { const yesterday = new Date(now - 24 * 60 * 60 * 1000); const yesterdayString = yesterday.toISOString().slice(0, 19).replace('T', ' '); + deleteExistingAttachments(); + const images = [] images.push({ title: 'Channel Health',