Instant DOTD

This commit is contained in:
ssyyhhrr
2023-01-02 03:38:07 +00:00
parent 380b30948d
commit 7cf236bdbd

17
app.js
View File

@@ -73,19 +73,13 @@ let year = new Date().getFullYear()
main()
schedule.scheduleJob("0 0 * * *", async () => {
schedule.scheduleJob("59 23 * * *", async () => {
axios.get("https://ergast.com/api/f1/1950/driverStandings.json?limit=1000").then(async () => {
await updateDrivers()
dotd()
}).catch(() => {
console.log("API is unreachable! Not updating drivers...")
if (fs.existsSync(driversPath)) {
let data = fs.readFileSync(driversPath)
drivers = JSON.parse(data)
dotd()
} else {
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 = JSON.parse(rawStatsFile)
@@ -99,6 +93,10 @@ schedule.scheduleJob("0 0 * * *", async () => {
}
})
schedule.scheduleJob("0 0 * * *", () => {
dotd()
})
async function main() {
axios.get("https://ergast.com/api/f1/1950/driverStandings.json?limit=1000").then(async () => {
await updateDrivers()
@@ -160,12 +158,13 @@ async function updateDrivers() {
function dotd() {
console.log("Selecting Driver of the Day...")
driver = getRandomProperty(drivers)
if (pastDrivers.includes(driver)) {
let newDriver = getRandomProperty(drivers)
if (pastDrivers.includes(newDriver)) {
console.log("Driver was picked recently, re-selecting...")
dotd()
return
}
driver = newDriver
pastDrivers.push(driver)
if (pastDrivers.length > 7) pastDrivers.shift()
console.log(`Driver of the Day is ${driver}!`)