|
|
@ -11,15 +11,16 @@ import ( |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
type Market struct { |
|
|
|
type Market struct { |
|
|
|
IsClosed bool |
|
|
|
regex *regexp.Regexp |
|
|
|
Dow map[string]string |
|
|
|
IsClosed bool |
|
|
|
Nasdaq map[string]string |
|
|
|
Dow map[string]string |
|
|
|
Sp500 map[string]string |
|
|
|
Nasdaq map[string]string |
|
|
|
Advances map[string]string |
|
|
|
Sp500 map[string]string |
|
|
|
Declines map[string]string |
|
|
|
Advances map[string]string |
|
|
|
Unchanged map[string]string |
|
|
|
Declines map[string]string |
|
|
|
Highs map[string]string |
|
|
|
Unchanged map[string]string |
|
|
|
Lows map[string]string |
|
|
|
Highs map[string]string |
|
|
|
|
|
|
|
Lows map[string]string |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
@ -34,6 +35,26 @@ func (self *Market) Initialize() *Market { |
|
|
|
self.Highs = make(map[string]string) |
|
|
|
self.Highs = make(map[string]string) |
|
|
|
self.Lows = make(map[string]string) |
|
|
|
self.Lows = make(map[string]string) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const any = `\s*<.+?>` |
|
|
|
|
|
|
|
const some = `<.+?` |
|
|
|
|
|
|
|
const space = `\s*` |
|
|
|
|
|
|
|
const color = `#([08c]{6});">\s*` |
|
|
|
|
|
|
|
const price = `([\d\.,]+)` |
|
|
|
|
|
|
|
const percent = `\(([\d\.,%]+)\)` |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rules := []string{ |
|
|
|
|
|
|
|
`(Dow)`, 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, |
|
|
|
|
|
|
|
`(Advances)`, 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, |
|
|
|
|
|
|
|
`(New Hi's)`, any, price, any, price, any, |
|
|
|
|
|
|
|
`(New Lo's)`, any, price, any, price, any, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.regex = regexp.MustCompile(strings.Join(rules, ``)) |
|
|
|
|
|
|
|
|
|
|
|
return self |
|
|
|
return self |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -83,26 +104,7 @@ func (self *Market) trim(body []byte) []byte { |
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
func (self *Market) extract(snippet []byte) *Market { |
|
|
|
func (self *Market) extract(snippet []byte) *Market { |
|
|
|
const any = `\s*<.+?>` |
|
|
|
matches := self.regex.FindAllStringSubmatch(string(snippet), -1) |
|
|
|
const some = `<.+?` |
|
|
|
|
|
|
|
const space = `\s*` |
|
|
|
|
|
|
|
const color = `#([08c]{6});">\s*` |
|
|
|
|
|
|
|
const price = `([\d\.,]+)` |
|
|
|
|
|
|
|
const percent = `\(([\d\.,%]+)\)` |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
regex := []string{ |
|
|
|
|
|
|
|
`(Dow)`, 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, |
|
|
|
|
|
|
|
`(Advances)`, 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, |
|
|
|
|
|
|
|
`(New Hi's)`, any, price, any, price, any, |
|
|
|
|
|
|
|
`(New Lo's)`, any, price, any, price, any, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
re := regexp.MustCompile(strings.Join(regex, ``)) |
|
|
|
|
|
|
|
matches := re.FindAllStringSubmatch(string(snippet), -1) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if len(matches) > 0 {
|
|
|
|
// if len(matches) > 0 {
|
|
|
|
// fmt.Printf("%d matches\n", len(matches[0]))
|
|
|
|
// fmt.Printf("%d matches\n", len(matches[0]))
|
|
|
@ -113,7 +115,6 @@ func (self *Market) extract(snippet []byte) *Market { |
|
|
|
// println(`No matches`)
|
|
|
|
// println(`No matches`)
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.Dow[`name`] = matches[0][1] |
|
|
|
self.Dow[`name`] = matches[0][1] |
|
|
|
self.Dow[`latest`] = matches[0][2] |
|
|
|
self.Dow[`latest`] = matches[0][2] |
|
|
|
self.Dow[`change`] = matches[0][4] |
|
|
|
self.Dow[`change`] = matches[0][4] |
|
|
|