Last active
September 27, 2024 10:44
-
-
Save neosarchizo/85c6e099e61b687eabd9961a3b824d69 to your computer and use it in GitHub Desktop.
Stanza - NBA schedule crawler for Google Calendar format
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://stanzacal.com/nba-warriors | |
const TEAM_NAME = "Warriors"; | |
const schedules = document.querySelectorAll(".MuiBox-root.css-1e0va2f"); | |
const START_YEAR = 2024; | |
console.log('Subject@Start date@Start time') | |
for (let i = 0; i < schedules.length; i++) { | |
const s = schedules[i]; | |
const description = s.querySelector( | |
"span.MuiTypography-root.MuiTypography-h5.MuiCardHeader-title" | |
).textContent; | |
const teams = description.split(" at "); | |
let isHome = teams[0] !== TEAM_NAME; | |
const opponent = isHome ? teams[0] : teams[1]; | |
let date = s | |
.querySelector("#calendar-event-location") | |
.textContent.split(" · ")[0]; | |
let dateParts = date.split(" | "); | |
let time = dateParts[1]; | |
if (time.indexOf(":") === 1) { | |
time = "0" + time; | |
} | |
dateParts = dateParts[0].split(", ")[1].split(" "); | |
let fullDate = ""; | |
let month = dateParts[0]; | |
let day = dateParts[1]; | |
if (day.length === 1) { | |
day = "0" + day; | |
} | |
let year = START_YEAR; | |
switch (month) { | |
case "Oct": { | |
month = "10"; | |
break; | |
} | |
case "Nov": { | |
month = "11"; | |
break; | |
} | |
case "Dec": { | |
month = "12"; | |
break; | |
} | |
case "Jan": { | |
month = "01"; | |
year += 1; | |
break; | |
} | |
case "Feb": { | |
month = "02"; | |
year += 1; | |
break; | |
} | |
case "Mar": { | |
month = "03"; | |
year += 1; | |
break; | |
} | |
case "Apr": { | |
month = "04"; | |
year += 1; | |
break; | |
} | |
} | |
console.log(`[${TEAM_NAME}] ${isHome ? '(Home)' : '(Away)'} ${opponent}@${month}/${day}/${year}@${time}`); | |
// 1. Insert result in Excel | |
// 2. Split the column by '@' character | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment