mirror of
https://github.com/ArvinLovegood/go-stock.git
synced 2025-07-19 00:00:09 +08:00
feat(app): 更新股票信息显示和隐藏功能
- 在股票信息更新时,如果总价格不为0,设置系统托盘提示信息- 修复了显示和隐藏应用程序的功能 - 优化了股票数据 API 的请求 URL - 替换 ioutil 包为 io 包,以适应 Go 1.16 及以上版本
This commit is contained in:
parent
e3e06d342b
commit
5bc7cfab0a
16
app.go
16
app.go
@ -159,11 +159,13 @@ func MonitorStockPrices(a *App) {
|
||||
go runtime.EventsEmit(a.ctx, "stock_price", stockInfo)
|
||||
}
|
||||
}
|
||||
if total != 0 {
|
||||
title := "go-stock " + time.Now().Format(time.DateTime) + fmt.Sprintf(" %.2f¥", total)
|
||||
systray.SetTooltip(title)
|
||||
}
|
||||
|
||||
//title := "go-stock " + time.Now().Format(time.DateTime) + fmt.Sprintf(" %.2f¥", total)
|
||||
go runtime.EventsEmit(a.ctx, "realtime_profit", fmt.Sprintf(" %.2f", total))
|
||||
//runtime.WindowSetTitle(a.ctx, title)
|
||||
//systray.SetTooltip(title)
|
||||
|
||||
}
|
||||
func GetStockInfos(follows ...data.FollowedStock) *[]data.StockInfo {
|
||||
@ -443,7 +445,7 @@ func onReady(a *App) {
|
||||
systray.SetTooltip("go-stock 股票行情实时获取")
|
||||
// 创建菜单项
|
||||
show := systray.AddMenuItem("显示", "显示应用程序")
|
||||
//hide := systray.AddMenuItem("隐藏", "隐藏应用程序")
|
||||
hide := systray.AddMenuItem("隐藏", "隐藏应用程序")
|
||||
systray.AddSeparator()
|
||||
mQuitOrig := systray.AddMenuItem("退出", "退出应用程序")
|
||||
|
||||
@ -458,10 +460,10 @@ func onReady(a *App) {
|
||||
case <-show.ClickedCh:
|
||||
logger.SugaredLogger.Infof("显示应用程序")
|
||||
runtime.WindowShow(a.ctx)
|
||||
//runtime.WindowShow(a.ctx)
|
||||
//case <-hide.ClickedCh:
|
||||
// logger.SugaredLogger.Infof("隐藏应用程序")
|
||||
// runtime.Hide(a.ctx)
|
||||
//runtime.WindowShow(a.ctx)
|
||||
case <-hide.ClickedCh:
|
||||
logger.SugaredLogger.Infof("隐藏应用程序")
|
||||
runtime.WindowHide(a.ctx)
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -21,14 +21,13 @@ import (
|
||||
"golang.org/x/text/transform"
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/plugin/soft_delete"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// http://hq.sinajs.cn/rn=1730966120830&list=sh600000,sh600859
|
||||
const sina_stook_url = "http://hq.sinajs.cn/rn=%d&list=%s"
|
||||
const tushare_api_url = "http://api.tushare.pro"
|
||||
const sinaStockUrl = "http://hq.sinajs.cn/rn=%d&list=%s"
|
||||
const tushareApiUrl = "http://api.tushare.pro"
|
||||
const TushareToken = "9125ec636217a99a3218a64fc63507e95205f2666590792923cbaedf"
|
||||
|
||||
type StockDataApi struct {
|
||||
@ -197,7 +196,7 @@ func (receiver StockDataApi) GetIndexBasic() {
|
||||
Params: nil,
|
||||
Fields: fields}).
|
||||
SetResult(res).
|
||||
Post(tushare_api_url)
|
||||
Post(tushareApiUrl)
|
||||
if err != nil {
|
||||
logger.SugaredLogger.Error(err.Error())
|
||||
return
|
||||
@ -242,7 +241,7 @@ func (receiver StockDataApi) GetStockBaseInfo() {
|
||||
Fields: fields,
|
||||
}).
|
||||
SetResult(res).
|
||||
Post(tushare_api_url)
|
||||
Post(tushareApiUrl)
|
||||
//logger.SugaredLogger.Infof("GetStockBaseInfo %s", string(resp.Body()))
|
||||
//resp.Body()写入文件
|
||||
//ioutil.WriteFile("stock_basic.json", resp.Body(), 0666)
|
||||
@ -281,7 +280,7 @@ func (receiver StockDataApi) GetStockCodeRealTimeData(StockCodes ...string) (*[]
|
||||
SetHeader("Host", "hq.sinajs.cn").
|
||||
SetHeader("Referer", "https://finance.sina.com.cn/").
|
||||
SetHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36 Edg/119.0.0.0").
|
||||
Get(fmt.Sprintf(sina_stook_url, time.Now().Unix(), slice.Join(StockCodes, ",")))
|
||||
Get(fmt.Sprintf(sinaStockUrl, time.Now().Unix(), slice.Join(StockCodes, ",")))
|
||||
if err != nil {
|
||||
logger.SugaredLogger.Error(err.Error())
|
||||
return &[]StockInfo{}, err
|
||||
@ -393,10 +392,10 @@ func (receiver StockDataApi) GetStockList(key string) []StockBasic {
|
||||
return result
|
||||
}
|
||||
|
||||
// GB18030 转换为 UTF8
|
||||
// GB18030ToUTF8 GB18030 转换为 UTF8
|
||||
func GB18030ToUTF8(bs []byte) string {
|
||||
reader := transform.NewReader(bytes.NewReader(bs), simplifiedchinese.GB18030.NewDecoder())
|
||||
d, err := ioutil.ReadAll(reader)
|
||||
d, err := io.ReadAll(reader)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ func TestParseFullSingleStockData(t *testing.T) {
|
||||
SetHeader("Host", "hq.sinajs.cn").
|
||||
SetHeader("Referer", "https://finance.sina.com.cn/").
|
||||
SetHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36 Edg/119.0.0.0").
|
||||
Get(fmt.Sprintf(sina_stook_url, time.Now().Unix(), "sh600859,sh600745"))
|
||||
Get(fmt.Sprintf(sinaStockUrl, time.Now().Unix(), "sh600859,sh600745"))
|
||||
if err != nil {
|
||||
logger.SugaredLogger.Error(err.Error())
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user