Use of new Planet endpoint to get the planet name
This commit is contained in:
parent
321e6d0d33
commit
b320fbb580
1 changed files with 40 additions and 8 deletions
48
main.go
48
main.go
|
@ -321,21 +321,16 @@ func printCharacterPlanets(swaggerclient *ESI.App, m *Character) {
|
|||
|
||||
now := time.Now()
|
||||
|
||||
snIds := make([]int32, 0, len(planets))
|
||||
for _, planet := range planets {
|
||||
snIds = append(snIds, *planet.PlanetID)
|
||||
}
|
||||
planetNames := getUniverseNames(swaggerclient, &snIds)
|
||||
|
||||
for _, planet := range planets {
|
||||
pcallParam := ESIPlanetaryInteraction.NewGetCharactersCharacterIDPlanetsPlanetIDParams()
|
||||
pcallParam.WithCharacterID(m.CharacterID).WithPlanetID(*planet.PlanetID)
|
||||
|
||||
solarSystemInfo := getSolarSystemInformation(swaggerclient, *planet.SolarSystemID)
|
||||
planetName := planetNames[*planet.PlanetID]
|
||||
|
||||
planetName := getPlanetInformation(swaggerclient, *planet.PlanetID)
|
||||
|
||||
fmt.Printf(" Planet %s, %s - %s, level %d with %d structures - Updated %s\n",
|
||||
planetName,
|
||||
planetName.PlanetName,
|
||||
solarSystemInfo.SolarSystemName,
|
||||
*planet.PlanetType,
|
||||
*planet.UpgradeLevel, *planet.NumPins,
|
||||
|
@ -439,6 +434,43 @@ func getUniverseNames(swaggerclient *ESI.App, itemIds *[]int32) map[int32]string
|
|||
return itemNames
|
||||
}
|
||||
|
||||
type planetInformation struct {
|
||||
PlanetName string
|
||||
PlanetTypeID int32
|
||||
}
|
||||
|
||||
func getPlanetInformation(swaggerclient *ESI.App, planetID int32) planetInformation {
|
||||
|
||||
planetName := getCachedData(fmt.Sprintf("%d.name", planetID))
|
||||
planetType := getCachedData(fmt.Sprintf("%d.type", planetID))
|
||||
|
||||
if planetName == "" {
|
||||
pcallParams := ESIUniverse.NewGetUniversePlanetsPlanetIDParams()
|
||||
pcallParams.WithPlanetID(planetID)
|
||||
|
||||
pesiresponse, _ := swaggerclient.Universe.GetUniversePlanetsPlanetID(pcallParams)
|
||||
|
||||
planetESIInfo := pesiresponse.Payload
|
||||
|
||||
var planetInfo planetInformation
|
||||
planetInfo.PlanetName = *planetESIInfo.Name
|
||||
planetInfo.PlanetTypeID = *planetESIInfo.TypeID
|
||||
|
||||
putCacheData(fmt.Sprintf("%d.name", planetID), planetInfo.PlanetName)
|
||||
putCacheData(fmt.Sprintf("%d.type", planetID), fmt.Sprintf("%d.name", planetInfo.PlanetTypeID))
|
||||
|
||||
return planetInfo
|
||||
}
|
||||
|
||||
pPlanetType, _ := strconv.ParseInt(planetType, 10, 32)
|
||||
|
||||
var planetInfo planetInformation
|
||||
planetInfo.PlanetName = planetName
|
||||
planetInfo.PlanetTypeID = int32(pPlanetType)
|
||||
|
||||
return planetInfo
|
||||
}
|
||||
|
||||
// SolarSystemInfo - Structure to store and cache the Solar System information from ESI
|
||||
type SolarSystemInfo struct {
|
||||
SolarSystemName string
|
||||
|
|
Reference in a new issue