mirror of
https://github.com/Team254/cheesy-arena-lite.git
synced 2026-03-09 13:46:44 -04:00
Added retrieval of robot name from TBA.
This commit is contained in:
@@ -275,6 +275,11 @@ func getOfficialTeamInfo(teamId int) (*Team, error) {
|
||||
if tbaTeam.TeamNumber == 0 {
|
||||
team = Team{Id: teamId}
|
||||
} else {
|
||||
robotName, err := getRobotNameFromTba(teamId, 2015)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
recentAwards, err := getTeamAwardsFromTba(teamId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -290,9 +295,9 @@ func getOfficialTeamInfo(teamId int) (*Team, error) {
|
||||
}
|
||||
|
||||
// Use those variables to make a team object
|
||||
team = Team{Id: teamId, Name: tbaTeam.Name, Nickname: tbaTeam.Nickname,
|
||||
City: tbaTeam.Locality, StateProv: tbaTeam.Reigon,
|
||||
Country: tbaTeam.Country, RookieYear: tbaTeam.RookieYear, Accomplishments: accomplishmentsBuffer.String()}
|
||||
team = Team{Id: teamId, Name: tbaTeam.Name, Nickname: tbaTeam.Nickname, City: tbaTeam.Locality,
|
||||
StateProv: tbaTeam.Reigon, Country: tbaTeam.Country, RookieYear: tbaTeam.RookieYear,
|
||||
RobotName: robotName, Accomplishments: accomplishmentsBuffer.String()}
|
||||
}
|
||||
} else {
|
||||
// If team grab is disabled, just use the team number
|
||||
|
||||
30
tba.go
30
tba.go
@@ -18,6 +18,7 @@ import (
|
||||
// Distinct endpoints are necessary for testing.
|
||||
var tbaBaseUrl = "http://www.thebluealliance.com"
|
||||
var tbaTeamBaseUrl = tbaBaseUrl
|
||||
var tbaTeamRobotsBaseUrl = tbaBaseUrl
|
||||
var tbaTeamAwardsBaseUrl = tbaBaseUrl
|
||||
var tbaEventBaseUrl = tbaBaseUrl
|
||||
|
||||
@@ -70,6 +71,10 @@ type TbaTeam struct {
|
||||
Nickname string `json:"nickname"`
|
||||
}
|
||||
|
||||
type TbaRobot struct {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type TbaAward struct {
|
||||
Name string `json:"name"`
|
||||
EventKey string `json:"event_key"`
|
||||
@@ -103,6 +108,31 @@ func getTeamFromTba(teamNumber int) (*TbaTeam, error) {
|
||||
return &teamData, err
|
||||
}
|
||||
|
||||
func getRobotNameFromTba(teamNumber int, year int) (string, error) {
|
||||
url := fmt.Sprintf("%s/api/v2/team/frc%d/history/robots", tbaTeamRobotsBaseUrl, teamNumber)
|
||||
resp, err := getTbaRequest(url)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// Get the response and handle errors
|
||||
defer resp.Body.Close()
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
var robots map[string]TbaRobot
|
||||
err = json.Unmarshal(body, &robots)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if robotName, ok := robots[strconv.Itoa(year)]; ok {
|
||||
return robotName.Name, nil
|
||||
}
|
||||
return "", nil
|
||||
}
|
||||
|
||||
func getTeamAwardsFromTba(teamNumber int) ([]*TbaAward, error) {
|
||||
url := fmt.Sprintf("%s/api/v2/team/%s/history/awards", tbaTeamAwardsBaseUrl, getTbaTeam(teamNumber))
|
||||
resp, err := getTbaRequest(url)
|
||||
|
||||
Reference in New Issue
Block a user