Small simplification

master
Michael Dvorkin 11 years ago
parent 8e3b2292ce
commit ef65f51624
  1. 3
      layout.go
  2. 21
      yahoo_quotes.go

@ -82,7 +82,7 @@ func (self *Layout) Quotes(quotes *Quotes) string {
{{.Header}} {{.Header}}
{{range.Stocks}}{{.Color}}{{.Ticker}}{{.LastTrade}}{{.Change}}{{.ChangePct}}{{.Open}}{{.Low}}{{.High}}{{.Low52}}{{.High52}}{{.Volume}}{{.AvgVolume}}{{.PeRatio}}{{.Dividend}}{{.Yield}}{{.MarketCap}}{{.ResetColor}} {{range.Stocks}}{{if .Advancing}}<green>{{end}}{{.Ticker}}{{.LastTrade}}{{.Change}}{{.ChangePct}}{{.Open}}{{.Low}}{{.High}}{{.Low52}}{{.High52}}{{.Volume}}{{.AvgVolume}}{{.PeRatio}}{{.Dividend}}{{.Yield}}{{.MarketCap}}</>
{{end}}` {{end}}`
//markup += fmt.Sprintf("[%v]", quotes.profile.Grouped) //markup += fmt.Sprintf("[%v]", quotes.profile.Grouped)
template, err := template.New(`quotes`).Parse(markup) template, err := template.New(`quotes`).Parse(markup)
@ -135,6 +135,7 @@ func (self *Layout) prettify(quotes *Quotes) []Stock {
pretty[i].Dividend = pad(blank_currency(q.Dividend), self.columns[12].width) pretty[i].Dividend = pad(blank_currency(q.Dividend), self.columns[12].width)
pretty[i].Yield = pad(percent(q.Yield), self.columns[13].width) pretty[i].Yield = pad(percent(q.Yield), self.columns[13].width)
pretty[i].MarketCap = pad(currency(q.MarketCapX), self.columns[14].width) pretty[i].MarketCap = pad(currency(q.MarketCapX), self.columns[14].width)
pretty[i].Advancing = q.Advancing
} }
profile := quotes.profile profile := quotes.profile

@ -7,7 +7,6 @@ import (
`fmt` `fmt`
`io/ioutil` `io/ioutil`
`net/http` `net/http`
`strings`
) )
// See http://www.gummy-stuff.org/Yahoo-stocks.htm // See http://www.gummy-stuff.org/Yahoo-stocks.htm
@ -54,6 +53,7 @@ type Stock struct {
Yield string Yield string
MarketCap string MarketCap string
MarketCapX string MarketCapX string
Advancing bool
} }
type Quotes struct { type Quotes struct {
@ -138,6 +138,7 @@ func (self *Quotes) parse(body []byte) *Quotes {
self.stocks[i].Yield = string(columns[14]) self.stocks[i].Yield = string(columns[14])
self.stocks[i].MarketCap = string(columns[15]) self.stocks[i].MarketCap = string(columns[15])
self.stocks[i].MarketCapX = string(columns[16]) self.stocks[i].MarketCapX = string(columns[16])
self.stocks[i].Advancing = self.stocks[i].Change[0:1] != `-`
} }
return self return self
@ -147,21 +148,3 @@ func (self *Quotes) parse(body []byte) *Quotes {
func (self *Quotes) sanitize(body []byte) []byte { func (self *Quotes) sanitize(body []byte) []byte {
return bytes.Replace(bytes.TrimSpace(body), []byte{'"'}, []byte{}, -1) return bytes.Replace(bytes.TrimSpace(body), []byte{'"'}, []byte{}, -1)
} }
//-----------------------------------------------------------------------------
func (stock *Stock) Color() string {
if strings.Index(stock.Change, "-") == -1 {
return `<green>`
} else {
return ``
}
}
func (stock *Stock) ResetColor() string {
if strings.Index(stock.Change, "-") == -1 {
return `</>`
} else {
return ``
}
}

Loading…
Cancel
Save