The shit I do for w00t4me
This commit is contained in:
@ -40,7 +40,7 @@ func GetGameInfo(teamName, date string) string {
|
|||||||
// Check if the last 5 characters are in MM/DD format for date input
|
// Check if the last 5 characters are in MM/DD format for date input
|
||||||
if len(date) == 5 && unicode.IsDigit(rune(date[0])) && unicode.IsDigit(rune(date[1])) && date[2] == '/' &&
|
if len(date) == 5 && unicode.IsDigit(rune(date[0])) && unicode.IsDigit(rune(date[1])) && date[2] == '/' &&
|
||||||
unicode.IsDigit(rune(date[3])) && unicode.IsDigit(rune(date[4])) {
|
unicode.IsDigit(rune(date[3])) && unicode.IsDigit(rune(date[4])) {
|
||||||
date = fmt.Sprintf("2024/%s", strings.ReplaceAll(date, "/", "/")) // Add the year and reformat
|
date = fmt.Sprintf("2024/%s", date) // Add the year and format
|
||||||
} else {
|
} else {
|
||||||
return "Invalid date format. Please use MM/DD."
|
return "Invalid date format. Please use MM/DD."
|
||||||
}
|
}
|
||||||
@ -89,8 +89,16 @@ func fetchAndParseGames(apiURL, teamName string) string {
|
|||||||
game.Game.Home.Names.Short, game.Game.Home.Score,
|
game.Game.Home.Names.Short, game.Game.Home.Score,
|
||||||
currentPeriod, game.Game.ContestClock)
|
currentPeriod, game.Game.ContestClock)
|
||||||
} else if game.Game.GameState == "pre" {
|
} else if game.Game.GameState == "pre" {
|
||||||
gameInfo = fmt.Sprintf("Upcoming: %s @ %s on %s at %s ET",
|
startTime, err := time.Parse("03:04PM ET", game.Game.StartTime)
|
||||||
game.Game.Away.Names.Short, game.Game.Home.Names.Short, game.Game.StartDate, game.Game.StartTime)
|
if err == nil {
|
||||||
|
startTime = startTime.Add(-1 * time.Hour) // Subtract 1 hour for Central Time
|
||||||
|
formattedTime := startTime.Format("03:04 PM CT")
|
||||||
|
gameInfo = fmt.Sprintf("Upcoming: %s @ %s on %s at %s",
|
||||||
|
game.Game.Away.Names.Short, game.Game.Home.Names.Short, game.Game.StartDate, formattedTime)
|
||||||
|
} else {
|
||||||
|
gameInfo = fmt.Sprintf("Upcoming: %s @ %s on %s at %s",
|
||||||
|
game.Game.Away.Names.Short, game.Game.Home.Names.Short, game.Game.StartDate, game.Game.StartTime)
|
||||||
|
}
|
||||||
} else if game.Game.GameState == "final" {
|
} else if game.Game.GameState == "final" {
|
||||||
gameInfo = fmt.Sprintf("Final: %s: **%s** %s: **%s**",
|
gameInfo = fmt.Sprintf("Final: %s: **%s** %s: **%s**",
|
||||||
game.Game.Away.Names.Short, game.Game.Away.Score,
|
game.Game.Away.Names.Short, game.Game.Away.Score,
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
"unicode"
|
"unicode"
|
||||||
@ -16,6 +17,7 @@ type Game struct {
|
|||||||
GameID string `json:"gameID"`
|
GameID string `json:"gameID"`
|
||||||
StartDate string `json:"startDate"`
|
StartDate string `json:"startDate"`
|
||||||
StartTime string `json:"startTime"`
|
StartTime string `json:"startTime"`
|
||||||
|
StartTimeEpoch string `json:"startTimeEpoch"`
|
||||||
GameState string `json:"gameState"`
|
GameState string `json:"gameState"`
|
||||||
CurrentPeriod string `json:"currentPeriod"`
|
CurrentPeriod string `json:"currentPeriod"`
|
||||||
ContestClock string `json:"contestClock"`
|
ContestClock string `json:"contestClock"`
|
||||||
@ -33,22 +35,6 @@ type Team struct {
|
|||||||
} `json:"names"`
|
} `json:"names"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert time from Eastern to Central
|
|
||||||
func convertToCentralTime(easternTime string) (string, error) {
|
|
||||||
parsedTime, err := time.Parse("03:04PM ET", easternTime)
|
|
||||||
if err != nil {
|
|
||||||
return "", fmt.Errorf("error parsing time: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
centralLocation, err := time.LoadLocation("America/Chicago")
|
|
||||||
if err != nil {
|
|
||||||
return "", fmt.Errorf("error loading Central Time location: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
centralTime := parsedTime.In(centralLocation)
|
|
||||||
return centralTime.Format("03:04 PM"), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetGameInfo(teamName string) string {
|
func GetGameInfo(teamName string) string {
|
||||||
teamName = strings.TrimSpace(teamName)
|
teamName = strings.TrimSpace(teamName)
|
||||||
week := ""
|
week := ""
|
||||||
@ -107,10 +93,10 @@ func GetGameInfo(teamName string) string {
|
|||||||
game.Game.Home.Names.Short, game.Game.Home.Score,
|
game.Game.Home.Names.Short, game.Game.Home.Score,
|
||||||
period, game.Game.ContestClock)
|
period, game.Game.ContestClock)
|
||||||
} else if game.Game.GameState == "pre" {
|
} else if game.Game.GameState == "pre" {
|
||||||
centralTime, err := convertToCentralTime(game.Game.StartTime)
|
centralTime, err := convertEpochToCentralTime(game.Game.StartTimeEpoch)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Time conversion error: %v", err)
|
log.Printf("Time conversion error: %v", err)
|
||||||
centralTime = game.Game.StartTime // Fall back to the original if conversion fails
|
centralTime = game.Game.StartTime // Fall back to original time if conversion fails
|
||||||
}
|
}
|
||||||
gameInfo = fmt.Sprintf("Upcoming: %s @ %s on %s at %s CT",
|
gameInfo = fmt.Sprintf("Upcoming: %s @ %s on %s at %s CT",
|
||||||
game.Game.Away.Names.Short, game.Game.Home.Names.Short, game.Game.StartDate, centralTime)
|
game.Game.Away.Names.Short, game.Game.Home.Names.Short, game.Game.StartDate, centralTime)
|
||||||
@ -130,3 +116,21 @@ func GetGameInfo(teamName string) string {
|
|||||||
|
|
||||||
return "No game found for the specified team."
|
return "No game found for the specified team."
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func convertEpochToCentralTime(epochStr string) (string, error) {
|
||||||
|
epoch, err := strconv.ParseInt(epochStr, 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("error parsing epoch: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert the epoch time to time.Time and set it to Central Time
|
||||||
|
t := time.Unix(epoch, 0).UTC()
|
||||||
|
locCT, err := time.LoadLocation("America/Chicago")
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("error loading Central Time location: %w", err)
|
||||||
|
}
|
||||||
|
centralTime := t.In(locCT)
|
||||||
|
|
||||||
|
return centralTime.Format("03:04 PM"), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user