|
|
@ -68,7 +68,7 @@ func (self *Formatter) format_market(m *Market) string { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
func (self *Formatter) format_quotes(q *Quotes) string { |
|
|
|
func (self *Formatter) format_quotes(quotes *Quotes) string { |
|
|
|
vars := struct { |
|
|
|
vars := struct { |
|
|
|
Now string |
|
|
|
Now string |
|
|
|
Header string |
|
|
|
Header string |
|
|
@ -76,7 +76,7 @@ func (self *Formatter) format_quotes(q *Quotes) string { |
|
|
|
}{ |
|
|
|
}{ |
|
|
|
time.Now().Format(`3:04:05pm PST`), |
|
|
|
time.Now().Format(`3:04:05pm PST`), |
|
|
|
header(), |
|
|
|
header(), |
|
|
|
prettify(q.stocks), |
|
|
|
prettify(quotes), |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
markup := `<right><white>{{.Now}}</white></right> |
|
|
|
markup := `<right><white>{{.Now}}</white></right> |
|
|
@ -86,7 +86,7 @@ func (self *Formatter) format_quotes(q *Quotes) string { |
|
|
|
{{.Header}} |
|
|
|
{{.Header}} |
|
|
|
{{range .Stocks}}{{.Color}}{{.Ticker}} {{.LastTrade}} {{.Change}} {{.ChangePercent}} {{.Open}} {{.Low}} {{.High}} {{.Low52}} {{.High52}} {{.Volume}} {{.AvgVolume}} {{.PeRatio}} {{.Dividend}} {{.Yield}} {{.MarketCap}} |
|
|
|
{{range .Stocks}}{{.Color}}{{.Ticker}} {{.LastTrade}} {{.Change}} {{.ChangePercent}} {{.Open}} {{.Low}} {{.High}} {{.Low52}} {{.High52}} {{.Volume}} {{.AvgVolume}} {{.PeRatio}} {{.Dividend}} {{.Yield}} {{.MarketCap}} |
|
|
|
{{end}}` |
|
|
|
{{end}}` |
|
|
|
|
|
|
|
//markup += fmt.Sprintf("[%v]", quotes.profile.Grouped)
|
|
|
|
template, err := template.New(`quotes`).Parse(markup) |
|
|
|
template, err := template.New(`quotes`).Parse(markup) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
panic(err) |
|
|
|
panic(err) |
|
|
@ -123,9 +123,9 @@ func header() string { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
func prettify(stocks []Stock) []Stock { |
|
|
|
func prettify(quotes *Quotes) []Stock { |
|
|
|
pretty := make([]Stock, len(stocks)) |
|
|
|
pretty := make([]Stock, len(quotes.stocks)) |
|
|
|
for i, q := range stocks { |
|
|
|
for i, q := range group(quotes) { |
|
|
|
pretty[i].Ticker = pad(q.Ticker, -7) |
|
|
|
pretty[i].Ticker = pad(q.Ticker, -7) |
|
|
|
pretty[i].LastTrade = pad(with_currency(q.LastTrade), 9) |
|
|
|
pretty[i].LastTrade = pad(with_currency(q.LastTrade), 9) |
|
|
|
pretty[i].Change = pad(with_currency(q.Change), 9) |
|
|
|
pretty[i].Change = pad(with_currency(q.Change), 9) |
|
|
@ -145,6 +145,29 @@ func prettify(stocks []Stock) []Stock { |
|
|
|
return pretty |
|
|
|
return pretty |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
func group(quotes *Quotes) []Stock { |
|
|
|
|
|
|
|
if !quotes.profile.Grouped { |
|
|
|
|
|
|
|
return quotes.stocks |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
grouped := make([]Stock, len(quotes.stocks)) |
|
|
|
|
|
|
|
current := 0 |
|
|
|
|
|
|
|
for _,stock := range quotes.stocks { |
|
|
|
|
|
|
|
if strings.Index(stock.Change, "-") == -1 { |
|
|
|
|
|
|
|
grouped[current] = stock |
|
|
|
|
|
|
|
current++ |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
for _,stock := range quotes.stocks { |
|
|
|
|
|
|
|
if strings.Index(stock.Change, "-") != -1 { |
|
|
|
|
|
|
|
grouped[current] = stock |
|
|
|
|
|
|
|
current++ |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return grouped |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
func nullify(str string) string { |
|
|
|
func nullify(str string) string { |
|
|
|
if len(str) == 3 && str[0:3] == `N/A` { |
|
|
|
if len(str) == 3 && str[0:3] == `N/A` { |
|
|
|