Changing Drivers Fix

This commit is contained in:
ssyyhhrr
2023-03-16 01:42:33 +00:00
parent d68a147209
commit 1d658ec7e3

13
app.js
View File

@@ -147,11 +147,10 @@ async function updateDrivers() {
}) })
} }
function processStats() { function processStats(dotd = false) {
let date = dayjs().format("YYYY-MM-DD") let date = dayjs().format("YYYY-MM-DD")
let statsFile = {}
if (fs.existsSync(statsPath)) { if (fs.existsSync(statsPath)) {
statsFile = JSON.parse(fs.readFileSync(statsPath)) let statsFile = JSON.parse(fs.readFileSync(statsPath))
if (statsFile.hasOwnProperty(date)) { if (statsFile.hasOwnProperty(date)) {
if (statsFile[date]["visits"] < stats["visits"]) { if (statsFile[date]["visits"] < stats["visits"]) {
statsFile[date]["visits"] = stats["visits"] statsFile[date]["visits"] = stats["visits"]
@@ -168,13 +167,11 @@ function processStats() {
if (!statsFile[date].hasOwnProperty("driver") && stats.hasOwnProperty("driver")) { if (!statsFile[date].hasOwnProperty("driver") && stats.hasOwnProperty("driver")) {
statsFile[date]["driver"] = stats["driver"] statsFile[date]["driver"] = stats["driver"]
} }
} else { } else if (dotd) {
statsFile[date] = stats
}
} else {
statsFile[date] = stats statsFile[date] = stats
} }
fs.writeFileSync(statsPath, JSON.stringify(statsFile)) fs.writeFileSync(statsPath, JSON.stringify(statsFile))
}
} }
function dotd() { function dotd() {
@@ -201,7 +198,7 @@ function dotd() {
"guesses": 0, "guesses": 0,
"driver": driver "driver": driver
} }
processStats() processStats(true)
console.log(`Driver of the Day is ${driver}!`) console.log(`Driver of the Day is ${driver}!`)
console.log(drivers[driver]) console.log(drivers[driver])
} }