mirror of
https://github.com/ssyyhhrr/stewardle.git
synced 2025-11-15 21:33:49 -05:00
Instant DOTD
This commit is contained in:
17
app.js
17
app.js
@@ -73,19 +73,13 @@ let year = new Date().getFullYear()
|
|||||||
|
|
||||||
main()
|
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 () => {
|
axios.get("https://ergast.com/api/f1/1950/driverStandings.json?limit=1000").then(async () => {
|
||||||
await updateDrivers()
|
await updateDrivers()
|
||||||
dotd()
|
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
console.log("API is unreachable! Not updating drivers...")
|
console.log("API is unreachable! Not updating drivers...")
|
||||||
if (fs.existsSync(driversPath)) {
|
|
||||||
let data = fs.readFileSync(driversPath)
|
let data = fs.readFileSync(driversPath)
|
||||||
drivers = JSON.parse(data)
|
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 rawStatsFile = fs.readFileSync(statsPath)
|
||||||
let statsFile = JSON.parse(rawStatsFile)
|
let statsFile = JSON.parse(rawStatsFile)
|
||||||
@@ -99,6 +93,10 @@ schedule.scheduleJob("0 0 * * *", async () => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
schedule.scheduleJob("0 0 * * *", () => {
|
||||||
|
dotd()
|
||||||
|
})
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
axios.get("https://ergast.com/api/f1/1950/driverStandings.json?limit=1000").then(async () => {
|
axios.get("https://ergast.com/api/f1/1950/driverStandings.json?limit=1000").then(async () => {
|
||||||
await updateDrivers()
|
await updateDrivers()
|
||||||
@@ -160,12 +158,13 @@ async function updateDrivers() {
|
|||||||
|
|
||||||
function dotd() {
|
function dotd() {
|
||||||
console.log("Selecting Driver of the Day...")
|
console.log("Selecting Driver of the Day...")
|
||||||
driver = getRandomProperty(drivers)
|
let newDriver = getRandomProperty(drivers)
|
||||||
if (pastDrivers.includes(driver)) {
|
if (pastDrivers.includes(newDriver)) {
|
||||||
console.log("Driver was picked recently, re-selecting...")
|
console.log("Driver was picked recently, re-selecting...")
|
||||||
dotd()
|
dotd()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
driver = newDriver
|
||||||
pastDrivers.push(driver)
|
pastDrivers.push(driver)
|
||||||
if (pastDrivers.length > 7) pastDrivers.shift()
|
if (pastDrivers.length > 7) pastDrivers.shift()
|
||||||
console.log(`Driver of the Day is ${driver}!`)
|
console.log(`Driver of the Day is ${driver}!`)
|
||||||
|
|||||||
Reference in New Issue
Block a user