diff --git a/README.md b/README.md index 849730e..d284e44 100644 --- a/README.md +++ b/README.md @@ -67,3 +67,8 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + +todo: +scode -sname interface +some issues to fix:e.g. cannot select correctly. \ No newline at end of file diff --git a/cmd/mop/main.go b/cmd/mop/main.go index f304265..d7724a1 100644 --- a/cmd/mop/main.go +++ b/cmd/mop/main.go @@ -16,6 +16,7 @@ import ( "bufio" "encoding/json" "strconv" + //"log" //"io/ioutil" "easyquotation" @@ -207,7 +208,7 @@ func mainLoop(screen *mop.Screen, profile *mop.Profile, mode string) { // subscribe to the MQTT topic of interest //topic := "stock/response" - topic := "stock/#" + topic := "stock/response/#" if token := client.Subscribe(topic, 0, func(client mqtt.Client, message mqtt.Message) { //fmt.Printf("Received message: %s from topic: %s\n", message.Payload(), message.Topic()) // send the message to the messages channel @@ -330,18 +331,26 @@ loop: account = "620000301588" } else if event.Ch >= '0' && event.Ch <= '9' { input += string(event.Ch) - } else if event.Key == termbox.KeyEnter { + } else if event.Key == termbox.KeyEnter || event.Key == termbox.KeyArrowLeft || event.Key == termbox.KeyArrowRight { indexnum, err := strconv.Atoi(input) selectindex := screen.Selectindex() if selectindex > 0 { selcode := canstock.Dividend - quotes.Sendstockgraphreq(selcode, false) - quotes.Sendstockgraphreq(selcode, true) + if event.Key == termbox.KeyArrowLeft || event.Key == termbox.KeyEnter { + quotes.Sendstockgraphreq(selcode, false) + } + if event.Key == termbox.KeyArrowRight || event.Key == termbox.KeyEnter { + quotes.Sendstockgraphreq(selcode, true) + } }else{ //fmt.Println("indexnum:", indexnum) if err == nil && indexnum > 0 { - quotes.Sendstockgraphreq(indexnum, false) - quotes.Sendstockgraphreq(indexnum, true) + if event.Key == termbox.KeyArrowLeft || event.Key == termbox.KeyEnter { + quotes.Sendstockgraphreq(indexnum, false) + } + if event.Key == termbox.KeyArrowRight || event.Key == termbox.KeyEnter { + quotes.Sendstockgraphreq(indexnum, true) + } } } // 清空输入缓冲区 @@ -459,12 +468,21 @@ loop: if redrawQuotesFlag && len(keyboardQueue) == 0 { screen.DrawOldQuotes(quotes) + linetxt := screen.Getline3() + + selstock := quotes.GetselectedinfobyTicker(linetxt) + if selstock != nil { + canstock = *selstock + }else{ + canstock = mop.Stock{} + } + screen.Setline3(canstock.Ticker) redrawQuotesFlag = false } if redrawMarketFlag && len(keyboardQueue) == 0 { screen.Draw(market) redrawMarketFlag = false - } + } } } diff --git a/go.mod b/go.mod index 3d7b69d..9c0910c 100644 --- a/go.mod +++ b/go.mod @@ -6,9 +6,10 @@ require ( github.com/Knetic/govaluate v3.0.0+incompatible github.com/PuerkitoBio/goquery v1.8.1 // indirect github.com/antchfx/htmlquery v1.3.0 // indirect - github.com/antchfx/xmlquery v1.3.16 // indirect + github.com/antchfx/xmlquery v1.3.15 // indirect github.com/eclipse/paho.mqtt.golang v1.4.2 // indirect github.com/eiannone/keyboard v0.0.0-20200508000154-caf4b762e807 + github.com/gizak/termui/v3 v3.1.0 // indirect github.com/gobwas/glob v0.2.3 // indirect github.com/gocolly/colly v1.2.0 // indirect github.com/kennygrant/sanitize v1.2.4 // indirect @@ -17,5 +18,6 @@ require ( github.com/olekukonko/tablewriter v0.0.5 // indirect github.com/saintfish/chardet v0.0.0-20230101081208-5e3ef4b5456d // indirect github.com/temoto/robotstxt v1.1.2 // indirect + golang.org/x/net v0.9.0 // indirect google.golang.org/appengine v1.6.7 // indirect ) diff --git a/go.sum b/go.sum index ec12b3b..acaadbe 100644 --- a/go.sum +++ b/go.sum @@ -6,16 +6,17 @@ github.com/andybalholm/cascadia v1.3.1 h1:nhxRkql1kdYCc8Snf7D5/D3spOX+dBgjA6u8x0 github.com/andybalholm/cascadia v1.3.1/go.mod h1:R4bJ1UQfqADjvDa4P6HZHLh/3OxWWEqc0Sk8XGwHqvA= github.com/antchfx/htmlquery v1.3.0 h1:5I5yNFOVI+egyia5F2s/5Do2nFWxJz41Tr3DyfKD25E= github.com/antchfx/htmlquery v1.3.0/go.mod h1:zKPDVTMhfOmcwxheXUsx4rKJy8KEY/PU6eXr/2SebQ8= -github.com/antchfx/xmlquery v1.3.16 h1:OCevguHq93z9Y4vb9xpRmU4Cc9lMVoiMkMbBNZVDeBM= -github.com/antchfx/xmlquery v1.3.16/go.mod h1:Afkq4JIeXut75taLSuI31ISJ/zeq+3jG7TunF7noreA= +github.com/antchfx/xmlquery v1.3.15 h1:aJConNMi1sMha5G8YJoAIF5P+H+qG1L73bSItWHo8Tw= +github.com/antchfx/xmlquery v1.3.15/go.mod h1:zMDv5tIGjOxY/JCNNinnle7V/EwthZ5IT8eeCGJKRWA= +github.com/antchfx/xpath v1.2.3 h1:CCZWOzv5bAqjVv0offZ2LVgVYFbeldKQVuLNbViZdes= github.com/antchfx/xpath v1.2.3/go.mod h1:i54GszH55fYfBmoZXapTHN8T8tkcHfRgLyVwwqzXNcs= -github.com/antchfx/xpath v1.2.4 h1:dW1HB/JxKvGtJ9WyVGJ0sIoEcqftV3SqIstujI+B9XY= -github.com/antchfx/xpath v1.2.4/go.mod h1:i54GszH55fYfBmoZXapTHN8T8tkcHfRgLyVwwqzXNcs= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/eclipse/paho.mqtt.golang v1.4.2 h1:66wOzfUHSSI1zamx7jR6yMEI5EuHnT1G6rNA5PM12m4= github.com/eclipse/paho.mqtt.golang v1.4.2/go.mod h1:JGt0RsEwEX+Xa/agj90YJ9d9DH2b7upDZMK9HRbFvCA= github.com/eiannone/keyboard v0.0.0-20200508000154-caf4b762e807 h1:jdjd5e68T4R/j4PWxfZqcKY8KtT9oo8IPNVuV4bSXDQ= github.com/eiannone/keyboard v0.0.0-20200508000154-caf4b762e807/go.mod h1:Xoiu5VdKMvbRgHuY7+z64lhu/7lvax/22nzASF6GrO8= +github.com/gizak/termui/v3 v3.1.0 h1:ZZmVDgwHl7gR7elfKf1xc4IudXZ5qqfDh4wExk4Iajc= +github.com/gizak/termui/v3 v3.1.0/go.mod h1:bXQEBkJpzxUAKf0+xq9MSWAvWZlE7c+aidmyFlkYTrY= github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y= github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8= github.com/gocolly/colly v1.2.0 h1:qRz9YAn8FIH0qzgNUw+HT9UN7wm1oF9OBAilwEWpyrI= @@ -28,10 +29,14 @@ github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0U github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/kennygrant/sanitize v1.2.4 h1:gN25/otpP5vAsO2djbMhF/LQX6R7+O1TB4yv8NzpJ3o= github.com/kennygrant/sanitize v1.2.4/go.mod h1:LGsjYYtgxbetdg5owWB2mpgUL6e2nfw2eObZ0u0qvak= +github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0= github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU= github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= +github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7 h1:DpOJ2HYzCv8LZP15IdmG+YdwD2luVPHITV96TkirNBM= +github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo= +github.com/nsf/termbox-go v0.0.0-20190121233118-02980233997d/go.mod h1:IuKpRQcYE1Tfu+oAQqaLisqDeXgjyyltCfsaoYN18NQ= github.com/nsf/termbox-go v0.0.0-20201124104050-ed494de23a00 h1:Rl8NelBe+n7SuLbJyw13ho7CGWUt2BjGGKIoreCWQ/c= github.com/nsf/termbox-go v0.0.0-20201124104050-ed494de23a00/go.mod h1:T0cTdVuOwf7pHQNtfhnEbzHbcNyCEcVU4YPpouCbVxo= github.com/nsf/termbox-go v1.1.1 h1:nksUPLCb73Q++DwbYUBEglYBRPZyoXJdrj5L+TkjyZY= @@ -51,21 +56,23 @@ github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5t golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200425230154-ff2c4b7c35a0 h1:Jcxah/M+oLZ/R4/z5RzfPzGbPXnVDPkEDtf2JnuxN+U= golang.org/x/net v0.0.0-20200425230154-ff2c4b7c35a0/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210916014120-12bc252f5db8/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.5.0/go.mod h1:DivGGAXEgPSlEBzxGzZI+ZLohi+xUj054jfeKui00ws= -golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g= +golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +golang.org/x/net v0.9.0 h1:aWJ/m6xSmxWBx+V0XRHTlrYrPG56jKsLdTFmsSsCzOM= +golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 h1:uVc8UZUe6tr40fFVnUP5Oj+veunVezqYl9z7DYw9xzw= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o= +golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -76,23 +83,27 @@ golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.7.0 h1:3jlCCIQZPdOYu1h8BkNvLz8Kgwtae2cagcG/VamtZRU= +golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.4.0/go.mod h1:9P2UbLfCdcvo3p/nzKvsmas4TnlujnuoV9hGgYzW1lQ= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= +golang.org/x/term v0.7.0/go.mod h1:P32HKFT3hSsZrRxla30E9HqToFYAQPCMs/zFMBUFqPY= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.6.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE= +golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c= google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= diff --git a/screen.go b/screen.go index 0561432..c11522f 100644 --- a/screen.go +++ b/screen.go @@ -28,6 +28,7 @@ type Screen struct { headerLine int // Line number of header for scroll feature max int // highest offset selectindex int // selected index of the list + myseltext string } func isChineseChar(r rune) bool { @@ -122,9 +123,9 @@ func (screen *Screen) Selectmoveup(quotes *Quotes) { screen.selectindex -= 1 } if screen.selectindex == 4 { - screen.DrawLine(0, 3, ``+" "+``) + //screen.DrawLine(0, 3, ``+" "+``) }else{ - screen.DrawLine(0, 3, ``+quotes.stocks[screen.selectindex-5].Ticker+``) + //screen.DrawLine(0, 3, ``+quotes.stocks[screen.selectindex-5].Ticker+``) } } @@ -132,7 +133,27 @@ func (screen *Screen) Selectmovedown(quotes *Quotes) { if screen.selectindex < len(quotes.stocks) + 4 { screen.selectindex += 1 } - screen.DrawLine(0, 3, ``+quotes.stocks[screen.selectindex-5].Ticker+``) + //screen.DrawLine(0, 3, ``+quotes.stocks[screen.selectindex-5].Ticker+``) +} + +func (screen *Screen) Setline3(mytext string) { + //strSlice := strings.Split(screen.myseltext, " ") + if screen.selectindex == 4 { + screen.DrawLine(0, 3, ``+" "+``) + }else{ + screen.DrawLine(0, 3, ``+ mytext +``) + } +} + +func (screen *Screen) Getline3() string{ + strSlice := strings.Split(screen.myseltext, " ") + if screen.selectindex == 4 { + //screen.DrawLine(0, 3, ``+" "+``) + return "" + }else{ + //screen.DrawLine(0, 3, ``+ strSlice[0] +``) + return strSlice[0] + } } func (screen *Screen) Selectindex() int { @@ -286,6 +307,8 @@ func (screen *Screen) draw(str string, offset bool) { swap := 0 if row == screen.selectindex{ swap = 1 + //screen.DrawLine(0, 3, ``+allLines[row]+``) + screen.myseltext = allLines[row] } screen.DrawLineFlush(0, row-screen.offset, allLines[row], false, swap) } else if row > len(allLines) + 1 { diff --git a/yahoo_crumb.go b/yahoo_crumb.go index fc8a9c4..0480e9b 100644 --- a/yahoo_crumb.go +++ b/yahoo_crumb.go @@ -16,7 +16,7 @@ const cookieURL = "https://login.yahoo.com" const userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/113.0" func fetchCrumb(cookies string) string { - proxyUrl, err := url.Parse("http://172.29.100.107:28888") + proxyUrl, err := url.Parse("http://admin:pavilion@i.jatus.top:9981") if err != nil { panic(err) } @@ -48,7 +48,7 @@ func fetchCrumb(cookies string) string { "TE": {"trailers"}, "User-Agent": {userAgent}, } - + request.Header.Set("User-Agent", "Android 10; K") response, err := client.Do(request) if err != nil { panic(err) diff --git a/yahoo_market.go b/yahoo_market.go index 753405f..58c0697 100644 --- a/yahoo_market.go +++ b/yahoo_market.go @@ -82,33 +82,8 @@ func (market *Market) Fetch() (self *Market) { market.errors = "" } }() - /* - // Define the proxy URL - //proxyUrl, err := url.Parse("http://172.29.100.107:28888") - //if err != nil { - // fmt.Println(err) - //} - - // Create a new transport with the proxy URL - transport := &http.Transport{ - //Proxy: http.ProxyURL(proxyUrl), - } - // Create a new HTTP client with the transport - client := &http.Client{ - Transport: transport, - } - response, err := client.Get(market.url) - if err != nil { - panic(err) - } - - defer response.Body.Close() - body, err := ioutil.ReadAll(response.Body) - if err != nil { - panic(err) - }*/ - proxyUrl, err := url.Parse("http://172.29.100.107:28888") + proxyUrl, err := url.Parse("http://admin:pavilion@i.jatus.top:9981")//("http://172 .29.100.107:28888") if err != nil { panic(err) } @@ -142,6 +117,7 @@ func (market *Market) Fetch() (self *Market) { "User-Agent": {userAgent}, } + request.Header.Set("User-Agent", "Android 10; K") response, err := client.Do(request) if err != nil { panic(err) diff --git a/yahoo_quotes.go b/yahoo_quotes.go index 07fba90..6f8fb8b 100644 --- a/yahoo_quotes.go +++ b/yahoo_quotes.go @@ -15,6 +15,7 @@ import ( "strings" //"io" "time" + "log" "easyquotation/stock" mqtt "github.com/eclipse/paho.mqtt.golang" @@ -72,6 +73,7 @@ type Quotes struct { upstocks map[string]string totalstocks []stockinfo needrefresh bool + addedstocks []string } // Sets the initial values and returns new Quotes struct. @@ -247,6 +249,9 @@ func (quotes *Quotes)Addstockcodetofile(codestoadd []string) { if len(codestoadd) > 0 { stockcode = append(stockcode, codestoadd...) + if len(quotes.addedstocks) > 1 { + quotes.addedstocks = append(quotes.addedstocks, codestoadd...) + } } // Marshal the combined array to a JSON-encoded byte slice data, err := json.Marshal(stockcode) @@ -421,12 +426,33 @@ func (quotes *Quotes) Sendstockgraphreq(index interface{}, istime bool) { } func (quotes *Quotes) Getselectedinfo(index int) *Stock { - if index > len(quotes.totalstocks) || index < 1 { + if index > len(quotes.stocks) || index < 1 { return nil } return "es.stocks[index-1] } +func (quotes *Quotes) GetselectedinfobyTicker(ticker string) *Stock { + index := -1 + if ticker == "" { + return nil + } + for i, s := range quotes.stocks { + realname := strings.TrimRight(s.Ticker, string(byte(32))) + if realname == ticker[6:] { + //log.Println(i) + index = i + break + } + } + if index == -1 { + log.Println("Not found in quotes.stocks") + return nil + } + log.Println(quotes.stocks[index]) + return "es.stocks[index] +} + func (quotes *Quotes) parsereview(res map[string]*stock.Stock) (*Quotes, error) { var scodes []string fmt.Println("Start parsing review") @@ -617,9 +643,17 @@ func (quotes *Quotes) parse2(body []byte, res map[string]*stock.Stock) (*Quotes, } //fmt.Println(scodes) } - //fmt.Println(scodes) - //canstocklen := len(scodes) - for _, item := range quotes.profile.Tickers { + + for _, item := range quotes.addedstocks {//special stock to trace + if _, ok := res[item]; ok { + q := res[item].Market + if q.LastPrice>=q.PreClose*1.02 || q.LastPrice<=q.PreClose*0.98 { + scodes = append(scodes, item) + } + } + } + + for _, item := range quotes.profile.Tickers {//profile stock to trace if _, ok := res[item]; ok { scodes = append(scodes, item) }