From ef65f516244bc05f50283800cc0842b54cea27d2 Mon Sep 17 00:00:00 2001 From: Michael Dvorkin Date: Thu, 1 Aug 2013 16:54:36 -0700 Subject: [PATCH] Small simplification --- layout.go | 3 ++- yahoo_quotes.go | 21 ++------------------- 2 files changed, 4 insertions(+), 20 deletions(-) diff --git a/layout.go b/layout.go index 0c1051a..b4f5928 100644 --- a/layout.go +++ b/layout.go @@ -82,7 +82,7 @@ func (self *Layout) Quotes(quotes *Quotes) string { {{.Header}} -{{range.Stocks}}{{.Color}}{{.Ticker}}{{.LastTrade}}{{.Change}}{{.ChangePct}}{{.Open}}{{.Low}}{{.High}}{{.Low52}}{{.High52}}{{.Volume}}{{.AvgVolume}}{{.PeRatio}}{{.Dividend}}{{.Yield}}{{.MarketCap}}{{.ResetColor}} +{{range.Stocks}}{{if .Advancing}}{{end}}{{.Ticker}}{{.LastTrade}}{{.Change}}{{.ChangePct}}{{.Open}}{{.Low}}{{.High}}{{.Low52}}{{.High52}}{{.Volume}}{{.AvgVolume}}{{.PeRatio}}{{.Dividend}}{{.Yield}}{{.MarketCap}} {{end}}` //markup += fmt.Sprintf("[%v]", quotes.profile.Grouped) 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].Yield = pad(percent(q.Yield), self.columns[13].width) pretty[i].MarketCap = pad(currency(q.MarketCapX), self.columns[14].width) + pretty[i].Advancing = q.Advancing } profile := quotes.profile diff --git a/yahoo_quotes.go b/yahoo_quotes.go index be7db5f..bf5fb5b 100644 --- a/yahoo_quotes.go +++ b/yahoo_quotes.go @@ -7,7 +7,6 @@ import ( `fmt` `io/ioutil` `net/http` - `strings` ) // See http://www.gummy-stuff.org/Yahoo-stocks.htm @@ -54,6 +53,7 @@ type Stock struct { Yield string MarketCap string MarketCapX string + Advancing bool } type Quotes struct { @@ -138,6 +138,7 @@ func (self *Quotes) parse(body []byte) *Quotes { self.stocks[i].Yield = string(columns[14]) self.stocks[i].MarketCap = string(columns[15]) self.stocks[i].MarketCapX = string(columns[16]) + self.stocks[i].Advancing = self.stocks[i].Change[0:1] != `-` } return self @@ -147,21 +148,3 @@ func (self *Quotes) parse(body []byte) *Quotes { func (self *Quotes) sanitize(body []byte) []byte { return bytes.Replace(bytes.TrimSpace(body), []byte{'"'}, []byte{}, -1) } - -//----------------------------------------------------------------------------- -func (stock *Stock) Color() string { - if strings.Index(stock.Change, "-") == -1 { - return `` - } else { - return `` - } -} - -func (stock *Stock) ResetColor() string { - if strings.Index(stock.Change, "-") == -1 { - return `` - } else { - return `` - } -} -