Add industry summary
This commit is contained in:
parent
107ab2522f
commit
3ab7b0969e
2 changed files with 111 additions and 1 deletions
|
@ -26,6 +26,7 @@ var (
|
||||||
"esi-planets.manage_planets.v1",
|
"esi-planets.manage_planets.v1",
|
||||||
"esi-wallet.read_character_wallet.v1",
|
"esi-wallet.read_character_wallet.v1",
|
||||||
"esi-markets.read_character_orders.v1",
|
"esi-markets.read_character_orders.v1",
|
||||||
|
"esi-industry.read_character_jobs.v1",
|
||||||
"esi-location.read_location.v1",
|
"esi-location.read_location.v1",
|
||||||
"esi-clones.read_clones.v1",
|
"esi-clones.read_clones.v1",
|
||||||
"esi-universe.read_structures.v1",
|
"esi-universe.read_structures.v1",
|
||||||
|
|
111
main.go
111
main.go
|
@ -30,6 +30,7 @@ import (
|
||||||
ESI "./client"
|
ESI "./client"
|
||||||
|
|
||||||
ESIClones "./client/clones"
|
ESIClones "./client/clones"
|
||||||
|
ESIIndustry "./client/industry"
|
||||||
ESILocation "./client/location"
|
ESILocation "./client/location"
|
||||||
ESIMarket "./client/market"
|
ESIMarket "./client/market"
|
||||||
ESIPlanetaryInteraction "./client/planetary_interaction"
|
ESIPlanetaryInteraction "./client/planetary_interaction"
|
||||||
|
@ -125,6 +126,7 @@ func main() {
|
||||||
planetInfoChan := make(chan string)
|
planetInfoChan := make(chan string)
|
||||||
skillsInfoChan := make(chan string)
|
skillsInfoChan := make(chan string)
|
||||||
marketInfoChan := make(chan string)
|
marketInfoChan := make(chan string)
|
||||||
|
industryInfoChan := make(chan string)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
charInfoChan <- printCharacterInformation(swaggerclient, m)
|
charInfoChan <- printCharacterInformation(swaggerclient, m)
|
||||||
|
@ -146,6 +148,11 @@ func main() {
|
||||||
close(marketInfoChan)
|
close(marketInfoChan)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
industryInfoChan <- printCharacterIndustryJobs(swaggerclient, m)
|
||||||
|
close(industryInfoChan)
|
||||||
|
}()
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
skillsInfoChan <- printCharacterSkillQueue(swaggerclient, m)
|
skillsInfoChan <- printCharacterSkillQueue(swaggerclient, m)
|
||||||
close(skillsInfoChan)
|
close(skillsInfoChan)
|
||||||
|
@ -174,6 +181,11 @@ func main() {
|
||||||
for msg := range marketInfoChan {
|
for msg := range marketInfoChan {
|
||||||
fmt.Print(msg)
|
fmt.Print(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fmt.Printf("\n\nIndustry Jobs\n")
|
||||||
|
for msg := range industryInfoChan {
|
||||||
|
fmt.Print(msg)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func readConfigurationFile() (*InternalUtils.HTTPConfiguration, error) {
|
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: "'"}
|
ac := accounting.Accounting{Symbol: "ISK ", Precision: 0, Thousand: "'"}
|
||||||
|
|
||||||
var content string
|
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 {
|
for _, wallet := range wallets {
|
||||||
if wallet.Balance > 0 {
|
if wallet.Balance > 0 {
|
||||||
|
@ -681,6 +693,103 @@ func printCharacterMarketOrders(swaggerclient *ESI.App, m *Character) string {
|
||||||
return content
|
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 {
|
func getUniverseNames(swaggerclient *ESI.App, itemIds *[]int32) map[int32]string {
|
||||||
itemNames := make(map[int32]string)
|
itemNames := make(map[int32]string)
|
||||||
itemMissingNames := make(map[int32]string)
|
itemMissingNames := make(map[int32]string)
|
||||||
|
|
Reference in a new issue