Metrics Tracking Fix

This commit is contained in:
ssyyhhrr
2022-12-26 18:13:52 +00:00
parent ae6b6044d0
commit 91d7395418
2 changed files with 8 additions and 2 deletions

1
.gitignore vendored
View File

@@ -1,4 +1,5 @@
node_modules node_modules
driver.txt driver.txt
drivers.json drivers.json
stats.json
.idea .idea

9
app.js
View File

@@ -83,8 +83,13 @@ schedule.scheduleJob("0 0 * * *", async () => {
throw "Ergast API is unreachable and the drivers.json cache has not been built. Please try again when the Ergast API is online." throw "Ergast API is unreachable and the drivers.json cache has not been built. Please try again when the Ergast API is online."
} }
}) })
let rawStatsFile = fs.readFileSync(statsPath) let statsFile
let statsFile = JSON.parse(rawStatsFile) if (fs.existsSync(statsPath)) {
let rawStatsFile = fs.readFileSync(statsPath)
statsFile = JSON.parse(rawStatsFile)
} else {
statsFile = {}
}
let date = dayjs.format("YYYY-MM-DD") let date = dayjs.format("YYYY-MM-DD")
statsFile[date] = stats statsFile[date] = stats
let newStatsFile = JSON.stringify(statsFile) let newStatsFile = JSON.stringify(statsFile)