From 34190fe98babf58c02172568577d1eab6f0e89a6 Mon Sep 17 00:00:00 2001 From: Thomas Schwery Date: Mon, 6 Feb 2017 13:19:06 +0100 Subject: [PATCH] Planetary interaction: Colors and cleanup of code --- main.go | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/main.go b/main.go index 846280a..4397315 100644 --- a/main.go +++ b/main.go @@ -18,6 +18,7 @@ import ( "github.com/go-openapi/strfmt" "github.com/leekchan/accounting" + "github.com/logrusorgru/aurora" ESI "client" ESIPlanetaryInteraction "client/planetary_interaction" @@ -238,25 +239,31 @@ func printCharacterPlanets(swaggerclient *ESI.App, m *Character) { pesiresponse, pesierr := swaggerclient.PlanetaryInteraction.GetCharactersCharacterIDPlanetsPlanetID(pcallParam, nil) if pesierr != nil { - fmt.Println("Error while getting the planetary interaction information") - log.Fatalf("Error on CharactersCharacterIDPlanetsPlanetID: %s", pesierr) + fmt.Println(" Error while getting the planetary interaction information") + log.Printf("Error on CharactersCharacterIDPlanetsPlanetID: %s\n", pesierr) + continue } + for _, pin := range pesiresponse.Payload.Pins { if pin.ExtractorDetails != nil { - status := "✘" - if time.Time(pin.ExpiryTime).After(time.Now()) { - status = "✔" + status := fmt.Sprint(aurora.Red("✘").Bold()) + statuscomment := fmt.Sprint(aurora.Red("expired").Bold()) + duration := now.Sub(time.Time(pin.ExpiryTime)) + if time.Time(pin.ExpiryTime).After(now) { + status = fmt.Sprint(aurora.Green("✔").Bold()) + statuscomment = "expires" + duration = time.Time(pin.ExpiryTime).Sub(now) } - duration := time.Time(pin.ExpiryTime).Sub(now) - - fmt.Printf(" %s Extractor % 5ds cycle, % 6d per cycle, expires %s (%02d:%02d)\n", + fmt.Printf(" %s Extractor % 5ds cycle, % 6d per cycle, %s %s (%02dd%02d:%02d)\n", status, *pin.ExtractorDetails.CycleTime, *pin.ExtractorDetails.QtyPerCycle, + statuscomment, time.Time(pin.ExpiryTime).Format("_2 Jan 2006, 15:04"), - int32(duration.Minutes())/60, - int32(duration.Minutes())%60, + (int32(duration.Minutes()) / (60 * 24)), + (int32(duration.Minutes())/60)%24, + (int32(duration.Minutes()) % 60), ) } else if pin.SchematicID != 0 { @@ -267,14 +274,6 @@ func printCharacterPlanets(swaggerclient *ESI.App, m *Character) { schematicInfo.CycleTime, schematicInfo.SchematicName, ) - } else { - /* - fmt.Printf(" %d %d (%s)\n%v\n", - *pin.TypeID, - *pin.PinID, - pin.LastCycleStart, - pin) - */ } } }