Use of new Planet endpoint to get the planet name

This commit is contained in:
Thomas Schwery 2017-02-08 16:55:38 +01:00
parent 321e6d0d33
commit b320fbb580

48
main.go
View file

@ -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