mirror of
https://github.com/nprasad2077/NBA_Go.git
synced 2026-09-22 14:05:13 +00:00
workflows update
This commit is contained in:
@@ -60,25 +60,15 @@ func importPlayerTotalsPlayoffsScrape(db *gorm.DB) {
|
|||||||
|
|
||||||
// importGameSchedules fetches and stores game schedules
|
// importGameSchedules fetches and stores game schedules
|
||||||
func importGameSchedules(db *gorm.DB) {
|
func importGameSchedules(db *gorm.DB) {
|
||||||
// An NBA season typically runs from October to June
|
months := []string{"october", "november", "december"}
|
||||||
months := []string{
|
|
||||||
// "september", "october", "november", "december", "january",
|
|
||||||
// "february", "march", "april", "may", "june",
|
|
||||||
"may", "june",
|
|
||||||
// "february", "march", "april", "may", "june",
|
|
||||||
// "october", "november", "december",
|
|
||||||
}
|
|
||||||
|
|
||||||
for season := 2026; season <= 2026; season++ {
|
for season := 2006; season <= 2006; season++ {
|
||||||
log.Printf("--- Starting Game Schedule Import for Season: %d ---", season)
|
log.Printf("--- Starting Game Schedule Import for Season: %d ---", season)
|
||||||
for _, month := range months {
|
for _, month := range months {
|
||||||
// The service will print a warning and skip if a month has no data (e.g. May/June for a season not yet finished)
|
|
||||||
if err := services.FetchAndStoreGameSchedule(db, season, month); err != nil {
|
if err := services.FetchAndStoreGameSchedule(db, season, month); err != nil {
|
||||||
// Log the error but continue to the next month/season
|
|
||||||
log.Printf("Game schedule import failed for %s %d: %v", month, season, err)
|
log.Printf("Game schedule import failed for %s %d: %v", month, season, err)
|
||||||
}
|
}
|
||||||
log.Printf("Game schedule import for %s, %d complete.", month, season)
|
log.Printf("Game schedule import for %s, %d complete.", month, season)
|
||||||
// Respectful delay between requests
|
|
||||||
time.Sleep(2500 * time.Millisecond)
|
time.Sleep(2500 * time.Millisecond)
|
||||||
utils.SleepWithJitter(1800 * time.Millisecond)
|
utils.SleepWithJitter(1800 * time.Millisecond)
|
||||||
}
|
}
|
||||||
@@ -89,31 +79,26 @@ func importGameSchedules(db *gorm.DB) {
|
|||||||
// importBoxScores fetches and stores all box score data (line scores, player/team stats)
|
// importBoxScores fetches and stores all box score data (line scores, player/team stats)
|
||||||
// for games within a recent date range.
|
// for games within a recent date range.
|
||||||
func importBoxScores(db *gorm.DB) {
|
func importBoxScores(db *gorm.DB) {
|
||||||
// now := time.Now()
|
from := time.Date(2006, time.October, 1, 0, 0, 0, 0, time.UTC)
|
||||||
|
to := time.Date(2006, time.December, 15, 5, 30, 0, 0, time.UTC)
|
||||||
|
|
||||||
from := time.Date(2026, time.May, 25, 0, 0, 0, 0, time.UTC)
|
dateRangeComment := fmt.Sprintf("--- Starting Box Score Data Import for games between %s and %s ---",
|
||||||
// from := time.Date(now.Year(), now.Month(), now.Day()-1, 5, 30, 0, 0, time.UTC)
|
from.Format("January 2, 2006"),
|
||||||
to := time.Date(2026, time.June, 15, 5, 30, 0, 0, time.UTC)
|
to.Format("January 2, 2006"))
|
||||||
|
|
||||||
dateRangeComment := fmt.Sprintf("--- Starting Box Score Data Import for games between %s and %s ---",
|
log.Println(dateRangeComment)
|
||||||
from.Format("January 2, 2006"),
|
|
||||||
to.Format("January 2, 2006"))
|
|
||||||
|
|
||||||
log.Println(dateRangeComment)
|
if err := services.FetchAndStoreBoxScoreDataForDateRange(db, from, to); err != nil {
|
||||||
|
log.Fatalf("Box score import failed: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
if err := services.FetchAndStoreBoxScoreDataForDateRange(db, from, to); err != nil {
|
log.Println("--- Finished Box Score Data Import ---")
|
||||||
log.Fatalf("Box score import failed: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Println("--- Finished Box Score Data Import ---")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// importMarkPlayoffGames marks games as playoff using the dedicated Basketball Reference playoff schedule.
|
// importMarkPlayoffGames marks games as playoff using the dedicated Basketball Reference playoff schedule.
|
||||||
func importMarkPlayoffGames(db *gorm.DB) {
|
func importMarkPlayoffGames(db *gorm.DB) {
|
||||||
for season := 2026; season <= 2026; season++ {
|
for season := 2006; season <= 2006; season++ {
|
||||||
if err := services.FetchAndMarkPlayoffGames(db, season); err != nil {
|
if err := services.FetchAndMarkPlayoffGames(db, season+1); err != nil {
|
||||||
log.Printf("playoff marking failed for %d: %v", season, err)
|
log.Printf("playoff marking failed for %d: %v", season, err)
|
||||||
}
|
}
|
||||||
log.Printf("Playoff games marked for season: %d", season)
|
log.Printf("Playoff games marked for season: %d", season)
|
||||||
@@ -124,17 +109,9 @@ func importMarkPlayoffGames(db *gorm.DB) {
|
|||||||
func importPlayerShotCharts(db *gorm.DB) {
|
func importPlayerShotCharts(db *gorm.DB) {
|
||||||
log.Println("--- Starting Player Shot Chart Import from Predefined List ---")
|
log.Println("--- Starting Player Shot Chart Import from Predefined List ---")
|
||||||
|
|
||||||
// 1. Define the season range. Your service fetches from newest to oldest.
|
|
||||||
startSeason := 2026
|
startSeason := 2026
|
||||||
endSeason := 2017 // Basketball-Reference has data going back this far.
|
endSeason := 2017
|
||||||
|
|
||||||
// 2. Define the static list of player IDs to import.
|
|
||||||
// You can add or remove any Basketball-Reference player ID here.
|
|
||||||
// Examples:
|
|
||||||
// LeBron James: "jamesle01"
|
|
||||||
// Stephen Curry: "curryst01"
|
|
||||||
// Nikola Jokić: "jokicni01"
|
|
||||||
// Luka Dončić: "doncilu01"
|
|
||||||
targetPlayerIDs := []string{
|
targetPlayerIDs := []string{
|
||||||
"jamesle01",
|
"jamesle01",
|
||||||
"curryst01",
|
"curryst01",
|
||||||
@@ -144,23 +121,16 @@ func importPlayerShotCharts(db *gorm.DB) {
|
|||||||
"irvinky01",
|
"irvinky01",
|
||||||
"duranke01",
|
"duranke01",
|
||||||
"youngtr01",
|
"youngtr01",
|
||||||
// "lillada01",
|
|
||||||
"gilgesh01",
|
"gilgesh01",
|
||||||
"brunsja01",
|
"brunsja01",
|
||||||
"edwaran01",
|
"edwaran01",
|
||||||
"mitchdo01",
|
"mitchdo01",
|
||||||
// "bookede01",
|
|
||||||
"derozde01",
|
"derozde01",
|
||||||
// "aldrila01",
|
|
||||||
"westbru01",
|
"westbru01",
|
||||||
// "paulch01",
|
|
||||||
"butleji01",
|
"butleji01",
|
||||||
"davisan02",
|
"davisan02",
|
||||||
"leonaka01",
|
"leonaka01",
|
||||||
// "youngtr01",
|
|
||||||
"tatumja01",
|
"tatumja01",
|
||||||
|
|
||||||
// Add more player IDs here as needed
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(targetPlayerIDs) == 0 {
|
if len(targetPlayerIDs) == 0 {
|
||||||
@@ -170,17 +140,14 @@ func importPlayerShotCharts(db *gorm.DB) {
|
|||||||
|
|
||||||
log.Printf("Found %d players in the predefined list. Starting shot chart import for seasons %d down to %d.", len(targetPlayerIDs), startSeason, endSeason)
|
log.Printf("Found %d players in the predefined list. Starting shot chart import for seasons %d down to %d.", len(targetPlayerIDs), startSeason, endSeason)
|
||||||
|
|
||||||
// 3. Loop through each player ID and fetch their shot chart data.
|
|
||||||
for i, playerID := range targetPlayerIDs {
|
for i, playerID := range targetPlayerIDs {
|
||||||
log.Printf("(%d/%d) Importing shot charts for player: %s", i+1, len(targetPlayerIDs), playerID)
|
log.Printf("(%d/%d) Importing shot charts for player: %s", i+1, len(targetPlayerIDs), playerID)
|
||||||
|
|
||||||
err := services.FetchAndStoreShotChartScrapedForPlayer(db, playerID, startSeason, endSeason)
|
err := services.FetchAndStoreShotChartScrapedForPlayer(db, playerID, startSeason, endSeason)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Log the error but continue with the next player.
|
|
||||||
log.Printf("❌ Shot chart import failed for player %s: %v", playerID, err)
|
log.Printf("❌ Shot chart import failed for player %s: %v", playerID, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 4. Be a good internet citizen. Pause between scraping each player.
|
|
||||||
utils.SleepWithJitter(10000 * time.Millisecond)
|
utils.SleepWithJitter(10000 * time.Millisecond)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user