Some cleanup

master
Michael Dvorkin 12 years ago
parent a8e5c05cc1
commit a63708a82b
  1. 96
      lib/format.go
  2. 13
      lib/line_editor.go
  3. 20
      lib/profile.go
  4. 50
      lib/screen.go
  5. 72
      lib/yahoo_market.go
  6. 223
      lib/yahoo_quotes.go

@ -3,30 +3,30 @@
package mop package mop
import ( import (
"bytes" `bytes`
"fmt" `fmt`
"regexp" `regexp`
"strings" `strings`
"text/template" `text/template`
"time" `time`
) )
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
func FormatMarket(m Market) string { func FormatMarket(m Market) string {
markup := `{{.Dow.name}}: ` markup := `{{.Dow.name}}: `
if m.Dow[`change`][0:1] != "-" { if m.Dow[`change`][0:1] != `-` {
markup += `<green>{{.Dow.change}} ({{.Dow.percent}})</green> at {{.Dow.latest}}, ` markup += `<green>{{.Dow.change}} ({{.Dow.percent}})</green> at {{.Dow.latest}}, `
} else { } else {
markup += `"{{.Dow.change}}" ({{.Dow.percent}}) at {{.Dow.latest}}, ` markup += `"{{.Dow.change}}" ({{.Dow.percent}}) at {{.Dow.latest}}, `
} }
markup += `{{.Sp500.name}}: ` markup += `{{.Sp500.name}}: `
if m.Sp500[`change`][0:1] != "-" { if m.Sp500[`change`][0:1] != `-` {
markup += `<green>{{.Sp500.change}} ({{.Sp500.percent}})</green> at {{.Sp500.latest}}, ` markup += `<green>{{.Sp500.change}} ({{.Sp500.percent}})</green> at {{.Sp500.latest}}, `
} else { } else {
markup += `{{.Sp500.change}} ({{.Sp500.percent}}) at {{.Sp500.latest}}, ` markup += `{{.Sp500.change}} ({{.Sp500.percent}}) at {{.Sp500.latest}}, `
} }
markup += `{{.Nasdaq.name}}: ` markup += `{{.Nasdaq.name}}: `
if m.Nasdaq[`change`][0:1] != "-" { if m.Nasdaq[`change`][0:1] != `-` {
markup += `<green>{{.Nasdaq.change}} ({{.Nasdaq.percent}})</green> at {{.Nasdaq.latest}}` markup += `<green>{{.Nasdaq.change}} ({{.Nasdaq.percent}})</green> at {{.Nasdaq.latest}}`
} else { } else {
markup += `{{.Nasdaq.change}} ({{.Nasdaq.percent}}) at {{.Nasdaq.latest}}` markup += `{{.Nasdaq.change}} ({{.Nasdaq.percent}}) at {{.Nasdaq.latest}}`
@ -37,7 +37,7 @@ func FormatMarket(m Market) string {
markup += "\n" markup += "\n"
markup += `New highs: {{.Highs.nyse}} on NYSE and {{.Highs.nasdaq}} on Nasdaq. ` markup += `New highs: {{.Highs.nyse}} on NYSE and {{.Highs.nasdaq}} on Nasdaq. `
markup += `New lows: {{.Lows.nyse}} on NYSE and {{.Lows.nasdaq}} on Nasdaq.` markup += `New lows: {{.Lows.nyse}} on NYSE and {{.Lows.nasdaq}} on Nasdaq.`
template, err := template.New("market").Parse(markup) template, err := template.New(`market`).Parse(markup)
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -58,7 +58,7 @@ func FormatQuotes(quotes Quotes) string {
Header string Header string
Stocks Quotes Stocks Quotes
}{ }{
time.Now().Format("3:04:05pm PST"), time.Now().Format(`3:04:05pm PST`),
header(), header(),
prettify(quotes), prettify(quotes),
} }
@ -71,7 +71,7 @@ func FormatQuotes(quotes Quotes) string {
{{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}}`
template, err := template.New("quotes").Parse(markup) template, err := template.New(`quotes`).Parse(markup)
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -86,21 +86,21 @@ func FormatQuotes(quotes Quotes) string {
} }
func header() string { func header() string {
str := fmt.Sprintf("%-7s ", "Ticker") str := fmt.Sprintf(`%-7s `, `Ticker`)
str += fmt.Sprintf("%9s ", "Last") str += fmt.Sprintf(`%9s `, `Last`)
str += fmt.Sprintf("%9s ", "Change") str += fmt.Sprintf(`%9s `, `Change`)
str += fmt.Sprintf("%9s ", "%Change") str += fmt.Sprintf(`%9s `, `%Change`)
str += fmt.Sprintf("%9s ", "Open") str += fmt.Sprintf(`%9s `, `Open`)
str += fmt.Sprintf("%9s ", "Low") str += fmt.Sprintf(`%9s `, `Low`)
str += fmt.Sprintf("%9s ", "High") str += fmt.Sprintf(`%9s `, `High`)
str += fmt.Sprintf("%9s ", "52w Low") str += fmt.Sprintf(`%9s `, `52w Low`)
str += fmt.Sprintf("%9s ", "52w High") str += fmt.Sprintf(`%9s `, `52w High`)
str += fmt.Sprintf("%10s ", "Volume") str += fmt.Sprintf(`%10s `, `Volume`)
str += fmt.Sprintf("%10s ", "AvgVolume") str += fmt.Sprintf(`%10s `, `AvgVolume`)
str += fmt.Sprintf("%9s ", "P/E") str += fmt.Sprintf(`%9s `, `P/E`)
str += fmt.Sprintf("%9s ", "Dividend") str += fmt.Sprintf(`%9s `, `Dividend`)
str += fmt.Sprintf("%9s ", "Yield") str += fmt.Sprintf(`%9s `, `Yield`)
str += fmt.Sprintf("%10s", "MktCap") str += fmt.Sprintf(`%10s`, `MktCap`)
return str return str
} }
@ -128,15 +128,15 @@ func prettify(quotes Quotes) Quotes {
} }
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` {
return "-" return `-`
} else { } else {
return str return str
} }
} }
func last_of_pair(str string) string { func last_of_pair(str string) string {
if len(str) >= 6 && str[0:6] != "N/A - " { if len(str) >= 6 && str[0:6] != `N/A - ` {
return str return str
} else { } else {
return str[6:] return str[6:]
@ -144,41 +144,41 @@ func last_of_pair(str string) string {
} }
func with_currency(str string) string { func with_currency(str string) string {
if str == "N/A" || str == "0.00" { if str == `N/A` || str == `0.00` {
return "-" return `-`
} else { } else {
switch str[0:1] { switch str[0:1] {
case "+", "-": case `+`, `-`:
return str[0:1] + "$" + str[1:] return str[0:1] + `$` + str[1:]
default: default:
return "$" + str return `$` + str
} }
} }
} }
func with_percent(str string) string { func with_percent(str string) string {
if str == "N/A" { if str == `N/A` {
return "-" return `-`
} else { } else {
return str + "%" return str + `%`
} }
} }
func colorize(str string) string { func colorize(str string) string {
if str == "N/A" { if str == `N/A` {
return "-" return `-`
} else if str[0:1] == "-" { } else if str[0:1] == `-` {
return "<red>" + str + "</red>" return `<red>` + str + `</red>`
} else { } else {
return "<green>" + str + "</green>" return `<green>` + str + `</green>`
} }
} }
func ticker(str string, change string) string { func ticker(str string, change string) string {
if change[0:1] == "-" { if change[0:1] == `-` {
return "<red>" + str + "</red>" return `<red>` + str + `</red>`
} else { } else {
return "<green>" + str + "</green>" return `<green>` + str + `</green>`
} }
} }
@ -188,11 +188,11 @@ func pad(str string, width int) string {
if len(match) > 0 { if len(match) > 0 {
switch len(match[1]) { switch len(match[1]) {
case 2: case 2:
str = strings.Replace(str, match[1], match[1]+"0", 1) str = strings.Replace(str, match[1], match[1] + `0`, 1)
case 4, 5: case 4, 5:
str = strings.Replace(str, match[1], match[1][0:3], 1) str = strings.Replace(str, match[1], match[1][0:3], 1)
} }
} }
return fmt.Sprintf("%*s", width, str) return fmt.Sprintf(`%*s`, width, str)
} }

@ -3,10 +3,9 @@
package mop package mop
import ( import (
"fmt" `regexp`
"regexp" `strings`
"strings" `github.com/nsf/termbox-go`
"github.com/nsf/termbox-go"
) )
type LineEditor struct { type LineEditor struct {
@ -25,7 +24,7 @@ func (self *LineEditor) Prompt(command rune, profile *Profile) {
self.command = command self.command = command
self.profile = profile self.profile = profile
DrawLine(0, 3, "<white>"+self.prompt+"</white>") DrawLine(0, 3, `<white>` + self.prompt + `</white>`)
termbox.SetCursor(len(self.prompt), 3) termbox.SetCursor(len(self.prompt), 3)
termbox.Flush() termbox.Flush()
} }
@ -68,7 +67,7 @@ func (self *LineEditor) Handle(ev termbox.Event) bool {
self.insert_character(ev.Ch) self.insert_character(ev.Ch)
} }
} }
DrawLine(20,20, fmt.Sprintf("cursor: %02d [%s] %08d", self.cursor, self.input, ev.Ch)) //DrawLine(20,20, fmt.Sprintf(`cursor: %02d [%s] %08d`, self.cursor, self.input, ev.Ch))
return false return false
} }
@ -82,7 +81,7 @@ func (self *LineEditor) delete_previous_character() {
// Remove last input character. // Remove last input character.
self.input = self.input[ : len(self.input)-1] self.input = self.input[ : len(self.input)-1]
} }
DrawLine(len(self.prompt), 3, self.input + " ") // Erase last character. DrawLine(len(self.prompt), 3, self.input + ` `) // Erase last character.
self.move_left() self.move_left()
} }
} }

@ -3,14 +3,14 @@
package mop package mop
import ( import (
"sort" `sort`
"encoding/json" `encoding/json`
"io/ioutil" `io/ioutil`
"os/user" `os/user`
"strings" `strings`
) )
const moprc = "/.moprc" const moprc = `/.moprc`
type Profile struct { type Profile struct {
MarketRefresh int MarketRefresh int
@ -27,9 +27,9 @@ func (self *Profile) Initialize() *Profile {
// Set default values. // Set default values.
self.MarketRefresh = 12 self.MarketRefresh = 12
self.QuotesRefresh = 5 self.QuotesRefresh = 5
self.Tickers = []string{"AAPL", "C", "GOOG", "IBM", "KO", "ORCL", "V"} self.Tickers = []string{`AAPL`, `C`, `GOOG`, `IBM`, `KO`, `ORCL`, `V`}
self.SortBy = "Ticker" self.SortBy = `Ticker`
self.SortOrder = "Desc" self.SortOrder = `Desc`
self.Save() self.Save()
} else { } else {
json.Unmarshal(data, self) json.Unmarshal(data, self)
@ -48,7 +48,7 @@ func (self *Profile) Save() error {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
func (self *Profile) Quotes() string { func (self *Profile) Quotes() string {
return strings.Join(self.Tickers, "+") return strings.Join(self.Tickers, `+`)
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------

@ -3,11 +3,11 @@
package mop package mop
import ( import (
"github.com/michaeldv/just" `github.com/michaeldv/just`
"github.com/nsf/termbox-go" `github.com/nsf/termbox-go`
"regexp" `regexp`
"strings" `strings`
"time" `time`
) )
// Can combine attributes and a single color using bitwise OR. // Can combine attributes and a single color using bitwise OR.
@ -17,15 +17,15 @@ import (
// AttrReverse // AttrReverse
// //
var tags = map[string]termbox.Attribute{ var tags = map[string]termbox.Attribute{
"black": termbox.ColorBlack, `black`: termbox.ColorBlack,
"red": termbox.ColorRed, `red`: termbox.ColorRed,
"green": termbox.ColorGreen, `green`: termbox.ColorGreen,
"yellow": termbox.ColorYellow, `yellow`: termbox.ColorYellow,
"blue": termbox.ColorBlue, `blue`: termbox.ColorBlue,
"magenta": termbox.ColorMagenta, `magenta`: termbox.ColorMagenta,
"cyan": termbox.ColorCyan, `cyan`: termbox.ColorCyan,
"white": termbox.ColorWhite, `white`: termbox.ColorWhite,
"right": termbox.ColorDefault, `right`: termbox.ColorDefault,
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -42,8 +42,8 @@ func DrawQuotes(stocks string) {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
func DrawTime() { func DrawTime() {
now := time.Now().Format("3:04:05pm PST") now := time.Now().Format(`3:04:05pm PST`)
DrawLine(0, 0, "<right>"+now+"</right>") DrawLine(0, 0, `<right>` + now + `</right>`)
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -63,9 +63,9 @@ func DrawLine(x int, y int, str string) {
if tag, open := isTag(token); tag { if tag, open := isTag(token); tag {
key := tagName(token) key := tagName(token)
if value, ok := tags[key]; ok { if value, ok := tags[key]; ok {
token = "" token = ``
switch key { switch key {
case "right": case `right`:
right = open right = open
default: default:
if open { if open {
@ -105,28 +105,28 @@ func tagsRegexp() *regexp.Regexp {
arr := []string{} arr := []string{}
for tag, _ := range tags { for tag, _ := range tags {
arr = append(arr, "</?"+tag+">") arr = append(arr, `</?` + tag + `>`)
} }
return regexp.MustCompile(strings.Join(arr, "|")) return regexp.MustCompile(strings.Join(arr, `|`))
} }
// //
// Return true if a string looks like a tag. // Return true if a string looks like a tag.
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
func isTag(str string) (is bool, open bool) { func isTag(str string) (is bool, open bool) {
is = (len(str) > 3 && str[0:1] == "<" && str[len(str)-1:] == ">") is = (len(str) > 3 && str[0:1] == `<` && str[len(str)-1:] == `>`)
open = (is && str[1:2] != "/") open = (is && str[1:2] != `/`)
return return
} }
// //
// Extract tag name from the given tag, i.e. "<hello>" => "hello" // Extract tag name from the given tag, i.e. `<hello>` => `hello`
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
func tagName(str string) string { func tagName(str string) string {
if len(str) < 3 { if len(str) < 3 {
return "" return ``
} else if str[1:2] != "/" { } else if str[1:2] != `/` {
return str[1 : len(str)-1] return str[1 : len(str)-1]
} else { } else {
return str[2 : len(str)-1] return str[2 : len(str)-1]

@ -3,11 +3,11 @@
package mop package mop
import ( import (
"bytes" `bytes`
"io/ioutil" `io/ioutil`
"net/http" `net/http`
"regexp" `regexp`
"strings" `strings`
) )
type Market struct { type Market struct {
@ -40,10 +40,10 @@ func GetMarket() Market {
} }
func trim(body []byte) []byte { func trim(body []byte) []byte {
start := bytes.Index(body, []byte("<table id=\"yfimktsumm\"")) start := bytes.Index(body, []byte(`<table id="yfimktsumm"`))
finish := bytes.LastIndex(body, []byte("<table id=\"yfimktsumm\"")) finish := bytes.LastIndex(body, []byte(`<table id="yfimktsumm"`))
snippet := bytes.Replace(body[start:finish], []byte{'\n'}, []byte{}, -1) snippet := bytes.Replace(body[start:finish], []byte{'\n'}, []byte{}, -1)
snippet = bytes.Replace(snippet, []byte("&amp;"), []byte{'&'}, -1) snippet = bytes.Replace(snippet, []byte(`&amp;`), []byte{'&'}, -1)
return snippet return snippet
} }
@ -57,17 +57,17 @@ func extract(snippet []byte) Market {
const percent = `\(([\d\.,%]+)\)` const percent = `\(([\d\.,%]+)\)`
regex := []string{ regex := []string{
"(Dow)", any, price, some, color, price, some, percent, any, `(Dow)`, any, price, some, color, price, some, percent, any,
"(Nasdaq)", any, price, some, color, price, some, percent, any, `(Nasdaq)`, any, price, some, color, price, some, percent, any,
"(S&P 500)", any, price, some, color, price, some, percent, any, `(S&P 500)`, any, price, some, color, price, some, percent, any,
"(Advances)", any, price, space, percent, any, price, space, percent, any, `(Advances)`, any, price, space, percent, any, price, space, percent, any,
"(Declines)", any, price, space, percent, any, price, space, percent, any, `(Declines)`, any, price, space, percent, any, price, space, percent, any,
"(Unchanged)", any, price, space, percent, any, price, space, percent, any, `(Unchanged)`, any, price, space, percent, any, price, space, percent, any,
"(New Hi's)", any, price, any, price, any, `(New Hi's)`, any, price, any, price, any,
"(New Lo's)", any, price, any, price, any, `(New Lo's)`, any, price, any, price, any,
} }
re := regexp.MustCompile(strings.Join(regex, "")) re := regexp.MustCompile(strings.Join(regex, ``))
matches := re.FindAllStringSubmatch(string(snippet), -1) matches := re.FindAllStringSubmatch(string(snippet), -1)
// if len(matches) > 0 { // if len(matches) > 0 {
@ -76,7 +76,7 @@ func extract(snippet []byte) Market {
// fmt.Printf("%d) [%s]\n", i, str) // fmt.Printf("%d) [%s]\n", i, str)
// } // }
// } else { // } else {
// println("No matches") // println(`No matches`)
// } // }
m := Market{ m := Market{
@ -94,12 +94,12 @@ func extract(snippet []byte) Market {
m.Dow[`latest`] = matches[0][2] m.Dow[`latest`] = matches[0][2]
m.Dow[`change`] = matches[0][4] m.Dow[`change`] = matches[0][4]
switch matches[0][3] { switch matches[0][3] {
case "008800": case `008800`:
m.Dow[`change`] = "+" + matches[0][4] m.Dow[`change`] = `+` + matches[0][4]
m.Dow[`percent`] = "+" + matches[0][5] m.Dow[`percent`] = `+` + matches[0][5]
case "cc0000": case `cc0000`:
m.Dow[`change`] = "-" + matches[0][4] m.Dow[`change`] = `-` + matches[0][4]
m.Dow[`percent`] = "-" + matches[0][5] m.Dow[`percent`] = `-` + matches[0][5]
default: default:
m.Dow[`change`] = matches[0][4] m.Dow[`change`] = matches[0][4]
m.Dow[`percent`] = matches[0][5] m.Dow[`percent`] = matches[0][5]
@ -108,12 +108,12 @@ func extract(snippet []byte) Market {
m.Nasdaq[`name`] = matches[0][6] m.Nasdaq[`name`] = matches[0][6]
m.Nasdaq[`latest`] = matches[0][7] m.Nasdaq[`latest`] = matches[0][7]
switch matches[0][8] { switch matches[0][8] {
case "008800": case `008800`:
m.Nasdaq[`change`] = "+" + matches[0][9] m.Nasdaq[`change`] = `+` + matches[0][9]
m.Nasdaq[`percent`] = "+" + matches[0][10] m.Nasdaq[`percent`] = `+` + matches[0][10]
case "cc0000": case `cc0000`:
m.Nasdaq[`change`] = "-" + matches[0][9] m.Nasdaq[`change`] = `-` + matches[0][9]
m.Nasdaq[`percent`] = "-" + matches[0][10] m.Nasdaq[`percent`] = `-` + matches[0][10]
default: default:
m.Nasdaq[`change`] = matches[0][9] m.Nasdaq[`change`] = matches[0][9]
m.Nasdaq[`percent`] = matches[0][10] m.Nasdaq[`percent`] = matches[0][10]
@ -122,12 +122,12 @@ func extract(snippet []byte) Market {
m.Sp500[`name`] = matches[0][11] m.Sp500[`name`] = matches[0][11]
m.Sp500[`latest`] = matches[0][12] m.Sp500[`latest`] = matches[0][12]
switch matches[0][13] { switch matches[0][13] {
case "008800": case `008800`:
m.Sp500[`change`] = "+" + matches[0][14] m.Sp500[`change`] = `+` + matches[0][14]
m.Sp500[`percent`] = "+" + matches[0][15] m.Sp500[`percent`] = `+` + matches[0][15]
case "cc0000": case `cc0000`:
m.Sp500[`change`] = "-" + matches[0][14] m.Sp500[`change`] = `-` + matches[0][14]
m.Sp500[`percent`] = "-" + matches[0][15] m.Sp500[`percent`] = `-` + matches[0][15]
default: default:
m.Sp500[`change`] = matches[0][14] m.Sp500[`change`] = matches[0][14]
m.Sp500[`percent`] = matches[0][15] m.Sp500[`percent`] = matches[0][15]

@ -3,14 +3,19 @@
package mop package mop
import ( import (
"bytes" `bytes`
"fmt" `fmt`
"io/ioutil" `io/ioutil`
"net/http" `net/http`
"strings" `strings`
) )
// See http://www.gummy-stuff.org/Yahoo-data.htm // See http://www.gummy-stuff.org/Yahoo-data.htm
// Also http://query.yahooapis.com/v1/public/yql
// ?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20in(%22ALU%22,%22AAPL%22)
// &env=http%3A%2F%2Fdatatables.org%2Falltables.env
// &format=json'
//
// Current, Change, Open, High, Low, 52-W High, 52-W Low, Volume, AvgVolume, P/E, Yield, Market Cap. // Current, Change, Open, High, Low, 52-W High, 52-W Low, Volume, AvgVolume, P/E, Yield, Market Cap.
// l1: last trade // l1: last trade
// c6: change rt // c6: change rt
@ -31,11 +36,6 @@ import (
const yahoo_quotes_url = `http://download.finance.yahoo.com/d/quotes.csv?s=%s&f=,l1c6k2oghjkva2r2rdyj3j1` const yahoo_quotes_url = `http://download.finance.yahoo.com/d/quotes.csv?s=%s&f=,l1c6k2oghjkva2r2rdyj3j1`
// "AAPL", 417.42, "-3.38", "N/A - -0.80%", 420.33, 415.35, 423.29, 385.10, 705.07, 9788680, 15181900, N/A, 10.04, 11.00, 2.61, N/A, 391.8B
// "ALU", 1.83, "+0.07", "N/A - +3.98%", 1.77, 1.75, 1.83, 0.91, 2.01, 7957103, 11640700, N/A, N/A, 0.00, N/A, N/A, 4.156B
// "IBM", 194.93, "+1.68", "N/A - +0.87%", 192.83, 192.3501, 195.16, 181.85, 215.90, 2407971, 4376120, N/A, 13.33, 3.50, 1.81, N/A, 216.1B
// "TSLA", 120.09, "+4.85", "N/A - +4.21%", 118.75, 115.70, 120.28, 25.52, 121.89, 6827497, 9464530, N/A, N/A, 0.00, N/A, N/A, 13.877B
type Quote struct { type Quote struct {
Ticker string Ticker string
LastTrade string LastTrade string
@ -60,7 +60,6 @@ type Quotes []Quote
func GetQuotes(tickers string) Quotes { func GetQuotes(tickers string) Quotes {
// Format the URL and send the request. // Format the URL and send the request.
// url := fmt.Sprintf(yahoo_quotes_url, strings.Join(tickers, "+"))
url := fmt.Sprintf(yahoo_quotes_url, tickers) url := fmt.Sprintf(yahoo_quotes_url, tickers)
response, err := http.Get(url) response, err := http.Get(url)
if err != nil { if err != nil {
@ -79,9 +78,9 @@ func GetQuotes(tickers string) Quotes {
func (q *Quote) Color() string { func (q *Quote) Color() string {
if strings.Index(q.Change, "-") == -1 { if strings.Index(q.Change, "-") == -1 {
return "</green><green>" return `</green><green>`
} else { } else {
return "" // "</red><red>" return `` // `</red><red>`
} }
} }
@ -122,201 +121,3 @@ func parse_line(line []byte, quote *Quote) {
quote.MarketCap = string(columns[15]) quote.MarketCap = string(columns[15])
quote.MarketCapX = string(columns[16]) quote.MarketCapX = string(columns[16])
} }
// func (quotes Quotes) Format() string {
// str := time.Now().Format("3:04:05pm PST\n")
//
// for _, q := range quotes {
// str += fmt.Sprintf("%s - %s - %s - %s\n", q.Ticker, q.Ask, q.Change, q.ChangePercent)
// }
// return str
// }
//
// http://query.yahooapis.com/v1/public/yql
// ?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20in(%22ALU%22,%22AAPL%22)
// &env=http%3A%2F%2Fdatatables.org%2Falltables.env
// &format=json'
//
// ^IXIC NASDAQ composite
// ^GSPC S&P 500
//
// {
// "query": {
// "count": 2,
// "created": "2013-06-28T03:28:19Z",
// "lang": "en-US",
// "results": {
// "quote": [
// {
// "AfterHoursChangeRealtime": "N/A - N/A",
// "AnnualizedGain": null,
// "Ask": null,
// "AskRealtime": "1.91",
// "AverageDailyVolume": "11692300",
// "Bid": null,
// "BidRealtime": "1.86",
// "BookValue": "1.249",
// "Change": "+0.12",
// "ChangeFromFiftydayMovingAverage": "+0.1626",
// "ChangeFromTwoHundreddayMovingAverage": "+0.321",
// "ChangeFromYearHigh": "-0.16",
// "ChangeFromYearLow": "+0.94",
// "ChangePercentRealtime": "N/A - +6.94%",
// "ChangeRealtime": "+0.12",
// "Change_PercentChange": "+0.12 - +6.94%",
// "ChangeinPercent": "+6.94%",
// "Commission": null,
// "DaysHigh": "1.92",
// "DaysLow": "1.79",
// "DaysRange": "1.79 - 1.92",
// "DaysRangeRealtime": "N/A - N/A",
// "DaysValueChange": "- - +6.94%",
// "DaysValueChangeRealtime": "N/A - N/A",
// "DividendPayDate": "29-Jun-07",
// "DividendShare": "0.00",
// "DividendYield": null,
// "EBITDA": "802.7M",
// "EPSEstimateCurrentYear": "-0.30",
// "EPSEstimateNextQuarter": "-0.05",
// "EPSEstimateNextYear": "-0.07",
// "EarningsShare": "-1.213",
// "ErrorIndicationreturnedforsymbolchangedinvalid": null,
// "ExDividendDate": "31-May-07",
// "FiftydayMovingAverage": "1.6874",
// "HighLimit": null,
// "HoldingsGain": null,
// "HoldingsGainPercent": "- - -",
// "HoldingsGainPercentRealtime": "N/A - N/A",
// "HoldingsGainRealtime": null,
// "HoldingsValue": null,
// "HoldingsValueRealtime": null,
// "LastTradeDate": "6/27/2013",
// "LastTradePriceOnly": "1.85",
// "LastTradeRealtimeWithTime": "N/A - <b>1.85</b>",
// "LastTradeTime": "4:00pm",
// "LastTradeWithTime": "Jun 27 - <b>1.85</b>",
// "LowLimit": null,
// "MarketCapRealtime": null,
// "MarketCapitalization": "4.202B",
// "MoreInfo": "cnprmIed",
// "Name": "Alcatel-Lucent Co",
// "Notes": null,
// "OneyrTargetPrice": "2.16",
// "Open": "1.81",
// "OrderBookRealtime": null,
// "PEGRatio": "0.22",
// "PERatio": null,
// "PERatioRealtime": null,
// "PercebtChangeFromYearHigh": "-7.96%",
// "PercentChange": "+6.94%",
// "PercentChangeFromFiftydayMovingAverage": "+9.63%",
// "PercentChangeFromTwoHundreddayMovingAverage": "+20.99%",
// "PercentChangeFromYearLow": "+103.30%",
// "PreviousClose": "1.73",
// "PriceBook": "1.39",
// "PriceEPSEstimateCurrentYear": null,
// "PriceEPSEstimateNextYear": null,
// "PricePaid": null,
// "PriceSales": "0.21",
// "SharesOwned": null,
// "ShortRatio": "0.90",
// "StockExchange": "NYSE",
// "Symbol": "ALU",
// "TickerTrend": " +=-=+- ",
// "TradeDate": null,
// "TwoHundreddayMovingAverage": "1.529",
// "Volume": "34193168",
// "YearHigh": "2.01",
// "YearLow": "0.91",
// "YearRange": "0.91 - 2.01",
// "symbol": "ALU"
// },
// {
// "AfterHoursChangeRealtime": "N/A - N/A",
// "AnnualizedGain": null,
// "Ask": "393.45",
// "AskRealtime": "393.45",
// "AverageDailyVolume": "17939600",
// "Bid": "393.32",
// "BidRealtime": "393.32",
// "BookValue": "144.124",
// "Change": "-4.29",
// "ChangeFromFiftydayMovingAverage": "-37.81",
// "ChangeFromTwoHundreddayMovingAverage": "-111.877",
// "ChangeFromYearHigh": "-311.29",
// "ChangeFromYearLow": "+8.68",
// "ChangePercentRealtime": "N/A - -1.08%",
// "ChangeRealtime": "-4.29",
// "Change_PercentChange": "-4.29 - -1.08%",
// "ChangeinPercent": "-1.08%",
// "Commission": null,
// "DaysHigh": "401.39",
// "DaysLow": "393.54",
// "DaysRange": "393.54 - 401.39",
// "DaysRangeRealtime": "N/A - N/A",
// "DaysValueChange": "- - -1.08%",
// "DaysValueChangeRealtime": "N/A - N/A",
// "DividendPayDate": "May 16",
// "DividendShare": "7.95",
// "DividendYield": "2.00",
// "EBITDA": "57.381B",
// "EPSEstimateCurrentYear": "39.57",
// "EPSEstimateNextQuarter": "8.21",
// "EPSEstimateNextYear": "43.71",
// "EarningsShare": "41.896",
// "ErrorIndicationreturnedforsymbolchangedinvalid": null,
// "ExDividendDate": "Feb 7",
// "FiftydayMovingAverage": "431.59",
// "HighLimit": null,
// "HoldingsGain": null,
// "HoldingsGainPercent": "- - -",
// "HoldingsGainPercentRealtime": "N/A - N/A",
// "HoldingsGainRealtime": null,
// "HoldingsValue": null,
// "HoldingsValueRealtime": null,
// "LastTradeDate": "6/27/2013",
// "LastTradePriceOnly": "393.78",
// "LastTradeRealtimeWithTime": "N/A - <b>393.78</b>",
// "LastTradeTime": "4:00pm",
// "LastTradeWithTime": "Jun 27 - <b>393.78</b>",
// "LowLimit": null,
// "MarketCapRealtime": null,
// "MarketCapitalization": "369.6B",
// "MoreInfo": "cnsprmiIed",
// "Name": "Apple Inc.",
// "Notes": null,
// "OneyrTargetPrice": "539.54",
// "Open": "399.01",
// "OrderBookRealtime": null,
// "PEGRatio": "0.48",
// "PERatio": "9.50",
// "PERatioRealtime": null,
// "PercebtChangeFromYearHigh": "-44.15%",
// "PercentChange": "-1.08%",
// "PercentChangeFromFiftydayMovingAverage": "-8.76%",
// "PercentChangeFromTwoHundreddayMovingAverage": "-22.13%",
// "PercentChangeFromYearLow": "+2.25%",
// "PreviousClose": "398.07",
// "PriceBook": "2.76",
// "PriceEPSEstimateCurrentYear": "10.06",
// "PriceEPSEstimateNextYear": "9.11",
// "PricePaid": null,
// "PriceSales": "2.21",
// "SharesOwned": null,
// "ShortRatio": "1.50",
// "StockExchange": "NasdaqNM",
// "Symbol": "AAPL",
// "TickerTrend": " +--=== ",
// "TradeDate": null,
// "TwoHundreddayMovingAverage": "505.657",
// "Volume": "12050007",
// "YearHigh": "705.07",
// "YearLow": "385.10",
// "YearRange": "385.10 - 705.07",
// "symbol": "AAPL"
// }
// ]
// }
// }
// }

Loading…
Cancel
Save