From 1d658ec7e37c8ee42acafda92f2121e1f15339a8 Mon Sep 17 00:00:00 2001 From: ssyyhhrr <44934807+ssyyhhrr@users.noreply.github.com> Date: Thu, 16 Mar 2023 01:42:33 +0000 Subject: [PATCH] Changing Drivers Fix --- app.js | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/app.js b/app.js index 195d61c..2ad5739 100644 --- a/app.js +++ b/app.js @@ -147,11 +147,10 @@ async function updateDrivers() { }) } -function processStats() { +function processStats(dotd = false) { let date = dayjs().format("YYYY-MM-DD") - let statsFile = {} if (fs.existsSync(statsPath)) { - statsFile = JSON.parse(fs.readFileSync(statsPath)) + let statsFile = JSON.parse(fs.readFileSync(statsPath)) if (statsFile.hasOwnProperty(date)) { if (statsFile[date]["visits"] < stats["visits"]) { statsFile[date]["visits"] = stats["visits"] @@ -168,13 +167,11 @@ function processStats() { if (!statsFile[date].hasOwnProperty("driver") && stats.hasOwnProperty("driver")) { statsFile[date]["driver"] = stats["driver"] } - } else { + } else if (dotd) { statsFile[date] = stats } - } else { - statsFile[date] = stats + fs.writeFileSync(statsPath, JSON.stringify(statsFile)) } - fs.writeFileSync(statsPath, JSON.stringify(statsFile)) } function dotd() { @@ -201,7 +198,7 @@ function dotd() { "guesses": 0, "driver": driver } - processStats() + processStats(true) console.log(`Driver of the Day is ${driver}!`) console.log(drivers[driver]) }