From 3ab7b0969ee5a3b0c9ccacc6e9e27a0caae15a29 Mon Sep 17 00:00:00 2001 From: Thomas Schwery Date: Sat, 24 Jun 2017 16:11:07 +0000 Subject: [PATCH] Add industry summary --- internals/httpclient.go | 1 + main.go | 111 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 111 insertions(+), 1 deletion(-) diff --git a/internals/httpclient.go b/internals/httpclient.go index 1a01753..aa56896 100644 --- a/internals/httpclient.go +++ b/internals/httpclient.go @@ -26,6 +26,7 @@ var ( "esi-planets.manage_planets.v1", "esi-wallet.read_character_wallet.v1", "esi-markets.read_character_orders.v1", + "esi-industry.read_character_jobs.v1", "esi-location.read_location.v1", "esi-clones.read_clones.v1", "esi-universe.read_structures.v1", diff --git a/main.go b/main.go index b823aeb..71e5c58 100644 --- a/main.go +++ b/main.go @@ -30,6 +30,7 @@ import ( ESI "./client" ESIClones "./client/clones" + ESIIndustry "./client/industry" ESILocation "./client/location" ESIMarket "./client/market" ESIPlanetaryInteraction "./client/planetary_interaction" @@ -125,6 +126,7 @@ func main() { planetInfoChan := make(chan string) skillsInfoChan := make(chan string) marketInfoChan := make(chan string) + industryInfoChan := make(chan string) go func() { charInfoChan <- printCharacterInformation(swaggerclient, m) @@ -146,6 +148,11 @@ func main() { close(marketInfoChan) }() + go func() { + industryInfoChan <- printCharacterIndustryJobs(swaggerclient, m) + close(industryInfoChan) + }() + go func() { skillsInfoChan <- printCharacterSkillQueue(swaggerclient, m) close(skillsInfoChan) @@ -174,6 +181,11 @@ func main() { for msg := range marketInfoChan { fmt.Print(msg) } + + fmt.Printf("\n\nIndustry Jobs\n") + for msg := range industryInfoChan { + fmt.Print(msg) + } } func readConfigurationFile() (*InternalUtils.HTTPConfiguration, error) { @@ -327,7 +339,7 @@ func printCharacterInformation(swaggerclient *ESI.App, m *Character) string { ac := accounting.Accounting{Symbol: "ISK ", Precision: 0, Thousand: "'"} var content string - content = content + fmt.Sprintf("Name: %s\n", m.CharacterName) + content = content + fmt.Sprintf("Name: %s (%d)\n", m.CharacterName, m.CharacterID) for _, wallet := range wallets { if wallet.Balance > 0 { @@ -681,6 +693,103 @@ func printCharacterMarketOrders(swaggerclient *ESI.App, m *Character) string { return content } +func printCharacterIndustryJobs(swaggerclient *ESI.App, m *Character) string { + cloCallParams := ESIIndustry.NewGetCharactersCharacterIDIndustryJobsParams() + cloCallParams.WithCharacterID(m.CharacterID) + + cloresponse, cloerr := swaggerclient.Industry.GetCharactersCharacterIDIndustryJobs(cloCallParams, nil) + if cloerr != nil { + fmt.Println("Error while getting the current character industry jobs.") + log.Fatalf("Got error on GetCharactersCharacterIDIndustryJobs: %s", cloerr) + } + + ac := accounting.Accounting{Symbol: "", Precision: 0, Thousand: "'"} + + jobs := cloresponse.Payload + + ptIds := make([]int32, 0, len(jobs)) + for _, job := range jobs { + if job.ProductTypeID > 0 { + ptIds = append(ptIds, job.ProductTypeID) + } + } + productNames := getUniverseNames(swaggerclient, &ptIds) + + maxWidth, _ := terminal.Width() + // We need to add the length of the colors + maxWidth = maxWidth + uint(len(fmt.Sprint(aurora.Red("")))*1) + + lineFormat := fmt.Sprintf("%%.%ds\n", maxWidth) + + priresponse, prierr := swaggerclient.Market.GetMarketsPrices(nil) + if prierr != nil { + fmt.Println("Error while getting the current market prices.") + log.Fatalf("Got error on GetMarketsPrices: %s", cloerr) + } + + prices := priresponse.Payload + priIds := make(map[int32]float32) + for _, price := range prices { + priIds[*price.TypeID] = price.AdjustedPrice + } + + var content string + for _, job := range jobs { + var status string + + if *job.Status == "delivered" || *job.Status == "cancelled" { + continue + } else if *job.Status == "active" { + status = "➠" + } else if *job.Status == "paused" { + status = "↟" + } else if *job.Status == "ready" { + status = "✔" + } else { + status = "✘" + } + + remainingDuration := time.Time(*job.EndDate).Sub(time.Now()) + + if remainingDuration.Hours() <= 0 { + status = fmt.Sprint(aurora.Red(status).Bold()) + } else if remainingDuration.Hours() <= 72 { + status = fmt.Sprint(aurora.Magenta(status).Bold()) + } else { + status = fmt.Sprint(aurora.Green(status).Bold()) + } + + var durationInfo string + if remainingDuration < 0 { + durationInfo = " " + } else { + durationInfo = formatDuration(remainingDuration, 2) + } + + sInfo, sErr := getStructureStationInfo(swaggerclient, int64(*job.FacilityID)) + if sErr != nil { + fmt.Printf("Error on structure information read on structure %s\n", *job.FacilityID) + log.Fatalf("Got error on getStructureStationInfo: %T %s", sErr, sErr) + } + + totalEstimatedPrice := float32(*job.Runs) * priIds[job.ProductTypeID] + + line := fmt.Sprintf(" %s % 5d %- 20.20s ~ISK % 12s %s (%s) %s", + status, + *job.Runs, + productNames[job.ProductTypeID], + ac.FormatMoney(totalEstimatedPrice), + time.Time(*job.EndDate).Format(defaultDateFormat), + durationInfo, + sInfo.Name, + ) + + content = content + fmt.Sprintf(lineFormat, line) + } + + return content +} + func getUniverseNames(swaggerclient *ESI.App, itemIds *[]int32) map[int32]string { itemNames := make(map[int32]string) itemMissingNames := make(map[int32]string)