Skip to content

Commit

Permalink
Merge fb047e7 into 8c8d572
Browse files Browse the repository at this point in the history
  • Loading branch information
toomore committed Jul 8, 2017
2 parents 8c8d572 + fb047e7 commit 1e9d984
Show file tree
Hide file tree
Showing 38 changed files with 857 additions and 669 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ script:
- go test -bench=. -benchmem ./twse
- go test -bench=. -benchmem ./utils
- sh ./install_all_cmd.sh
- docker build -t toomore/gogrs:latest ./ ; cd ./docker-mini; sh ./make.sh
- sh ./make.sh; sh ./make_mini.sh;
- docker images
- docker run -it --rm toomore/gogrs:mini sh -c "gogrs_example; realtime; tradingdays_server -h; twsecache; twsereport;"
- docker run -it --rm toomore/gogrs:mini sh -c "gogrs example; gogrs realtime; gogrs server; gogrs cache; gogrs report;"
19 changes: 13 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,23 @@ MAINTAINER Toomore Chiang <toomore0929@gmail.com>

WORKDIR /go/src/github.com/toomore/gogrs/

ADD ./cmd ./cmd
ADD ./realtime ./realtime
ADD ./tradingdays ./tradingdays
ADD ./twse ./twse
ADD ./utils ./utils

ADD ./LICENSE ./
ADD ./README.md ./
ADD ./cmd/cache.go ./cmd/cache.go
ADD ./cmd/example.go ./cmd/example.go
ADD ./cmd/filter ./cmd/filter
ADD ./cmd/gendoc.go ./cmd/gendoc.go
ADD ./cmd/realtime.go ./cmd/realtime.go
ADD ./cmd/report.go ./cmd/report.go
ADD ./cmd/root.go ./cmd/root.go
ADD ./cmd/server.go ./cmd/server.go
ADD ./doc.go ./
ADD ./goclean.sh ./
ADD ./main.go ./main.go
ADD ./realtime ./realtime
ADD ./tradingdays ./tradingdays
ADD ./twse ./twse
ADD ./utils ./utils

VOLUME ["/go/bin"]

Expand Down
5 changes: 4 additions & 1 deletion docker-mini/Dockerfile → Dockerfile-mini
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@ WORKDIR /bin

ADD ./gogrs_bin ./

RUN apk update && apk add ca-certificates && \
RUN apk update && apk add ca-certificates bash-completion && \
cd /usr/share/bash-completion/completions && gogrs doc -b && \
rm -rf /var/cache/apk/* /var/lib/apk/* /etc/apk/cache/*

CMD ["/bin/bash", "-l"]
24 changes: 13 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ Cmd

![gogrs cmd demo](https://s3-ap-northeast-1.amazonaws.com/toomore/gogrs/gogrs_cmd_demo_20150615.png "gogrs cmd demo")

1. gogrs_example - [簡單範例測試](https://godoc.org/github.com/toomore/gogrs/cmd/gogrs_example)
2. realtime - [擷取盤中即時資訊與大盤、上櫃、寶島指數](https://godoc.org/github.com/toomore/gogrs/cmd/realtime)
3. twsereport - [每日收盤後產生符合選股條件的報告](https://godoc.org/github.com/toomore/gogrs/cmd/twsereport)
4. twsecache - [清除 twse cache](https://godoc.org/github.com/toomore/gogrs/cmd/twsecache)
5. tradingdays_server - [提供簡單的日期查詢 API Server](https://godoc.org/github.com/toomore/gogrs/cmd/tradingdays_server)
1. example - [簡單範例測試](cmd/docs/gogrs_example.md)
2. realtime - [擷取盤中即時資訊與大盤、上櫃、寶島指數](cmd/docs/gogrs_realtime.md)
3. report - [每日收盤後產生符合選股條件的報告](cmd/docs/gogrs_report.md)
4. cache - [清除 twse cache](cmd/docs/gogrs_cache.md)
5. server - [提供簡單的日期查詢 API Server](cmd/docs/gogrs_server.md)

相關的操作請參考 `-h` 的說明,或 [cmd/docs](cmd/docs/gogrs.md)

Docker
-------
Expand All @@ -37,23 +39,23 @@ Or ...

Build minify gogrs docker(`toomore/gogrs:mini`)

cd ./docker-mini; sh ./make.sh
cd ./build-mini.sh

Run `tradingdays_server`.
Run `tradingdays server`.

docker run -d -p 80:59123 toomore/gogrs tradingdays_server
docker run -d -p 80:59123 toomore/gogrs:mini gogrs server

Or login run other cmd

docker run -it toomore/gogrs
docker run -it toomore/gogrs:mini

Create a ramdisk volume

docker create -v /run/shm/:/run/shm --name ramdisk toomore/gogrs-mini
docker create -v /run/shm/:/run/shm --name ramdisk toomore/gogrs:mini

Run with ramdisk volume

docker run -it --volumes-from ramdisk toomore/gogrs
docker run -it --volumes-from ramdisk toomore/gogrs:mini

TODO
-----
Expand Down
2 changes: 2 additions & 0 deletions build-base.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
docker build -t toomore/gogrs:latest ./
9 changes: 9 additions & 0 deletions build-mini.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

docker run -it --rm -v $(pwd)/gogrs_bin:/gogrs_bin toomore/gogrs:latest \
sh -c "go get -v ./...;
cp /go/bin/gogrs /gogrs_bin;"

docker build -t toomore/gogrs:mini -f ./Dockerfile-mini ./

sudo rm -rf ./gogrs_bin
13 changes: 0 additions & 13 deletions cmd/README.md

This file was deleted.

78 changes: 78 additions & 0 deletions cmd/cache.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// Copyright © 2017 Toomore Chiang
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// 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.

package cmd

import (
"log"

"github.com/fatih/color"
"github.com/spf13/cobra"
"github.com/toomore/gogrs/utils"
)

func outputNote(note ...interface{}) {
color.Set(color.FgBlue, color.Bold)
log.Println(note...)
color.Unset()
}

func outputDone(note ...interface{}) {
color.Set(color.FgGreen, color.Bold)
log.Println(note...)
color.Unset()
}

// cacheCmd represents the cache command
var cacheCmd = &cobra.Command{
Use: "cache",
Short: "cache system",
Long: `快取機制`,
Run: func(cmd *cobra.Command, args []string) {
cmd.Help()
},
}

var cacheFlushAllCmd = &cobra.Command{
Use: "flushall",
Short: "flushall cache",
Long: `清除所有快取`,
Run: func(cmd *cobra.Command, args []string) {
var hCache = utils.NewHTTPCache(utils.GetOSRamdiskPath(""), "utf8")
outputNote("Clear Cache:", hCache.Dir, utils.TempFolderName)
hCache.FlushAll()
outputDone("Done!")
},
}

func init() {
RootCmd.AddCommand(cacheCmd)
cacheCmd.AddCommand(cacheFlushAllCmd)

// Here you will define your flags and configuration settings.

// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// cacheCmd.PersistentFlags().String("foo", "", "A help for foo")

// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// cacheCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}
27 changes: 0 additions & 27 deletions cmd/doc.go

This file was deleted.

24 changes: 24 additions & 0 deletions cmd/docs/gogrs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
## gogrs

擷取台灣上市股票股價資訊工具

### Synopsis


擷取台灣上市股票股價資訊工具.

### Options

```
--config string config file (default is $HOME/.gogrs.yaml)
-h, --help help for gogrs
```

### SEE ALSO
* [gogrs cache](gogrs_cache.md) - cache system
* [gogrs example](gogrs_example.md) - Show example
* [gogrs realtime](gogrs_realtime.md) - realtime info
* [gogrs report](gogrs_report.md) - daily report
* [gogrs server](gogrs_server.md) - run tradingdays server

###### Auto generated by spf13/cobra on 8-Jul-2017
30 changes: 30 additions & 0 deletions cmd/docs/gogrs_cache.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
## gogrs cache

cache system

### Synopsis


快取機制

```
gogrs cache [flags]
```

### Options

```
-h, --help help for cache
```

### Options inherited from parent commands

```
--config string config file (default is $HOME/.gogrs.yaml)
```

### SEE ALSO
* [gogrs](gogrs.md) - 擷取台灣上市股票股價資訊工具
* [gogrs cache flushall](gogrs_cache_flushall.md) - flushall cache

###### Auto generated by spf13/cobra on 8-Jul-2017
29 changes: 29 additions & 0 deletions cmd/docs/gogrs_cache_flushall.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
## gogrs cache flushall

flushall cache

### Synopsis


清除所有快取

```
gogrs cache flushall [flags]
```

### Options

```
-h, --help help for flushall
```

### Options inherited from parent commands

```
--config string config file (default is $HOME/.gogrs.yaml)
```

### SEE ALSO
* [gogrs cache](gogrs_cache.md) - cache system

###### Auto generated by spf13/cobra on 8-Jul-2017
29 changes: 29 additions & 0 deletions cmd/docs/gogrs_example.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
## gogrs example

Show example

### Synopsis


Show gogrs example.

```
gogrs example [flags]
```

### Options

```
-h, --help help for example
```

### Options inherited from parent commands

```
--config string config file (default is $HOME/.gogrs.yaml)
```

### SEE ALSO
* [gogrs](gogrs.md) - 擷取台灣上市股票股價資訊工具

###### Auto generated by spf13/cobra on 8-Jul-2017
40 changes: 40 additions & 0 deletions cmd/docs/gogrs_realtime.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
## gogrs realtime

realtime info

### Synopsis


盤中即時資訊

```
gogrs realtime [flags]
```

### Options

```
-l, --catelist 顯示上市/上櫃分類表
--color 色彩化 (default true)
--count 計算此次查詢的漲跌家數 (default true)
-h, --help help for realtime
-i, --index 顯示大盤、上櫃、寶島指數(default: false)
-n, --ncpu int 指定 CPU 數量,預設為實際 CPU 數量 (default 1)
--nonstop int 自動重複,單位秒數
-o, --otc string 上櫃股票代碼,可使用 ',' 分隔多組代碼,例:4406,8446
-e, --otccate string 上櫃股票類別,可使用 ',' 分隔多組代碼,例:02,14
--pt 計算花費時間
-t, --twse string 上市股票代碼,可使用 ',' 分隔多組代碼,例:2618,2329
-c, --twsecate string 上市股票類別,可使用 ',' 分隔多組代碼,例:11,15
```

### Options inherited from parent commands

```
--config string config file (default is $HOME/.gogrs.yaml)
```

### SEE ALSO
* [gogrs](gogrs.md) - 擷取台灣上市股票股價資訊工具

###### Auto generated by spf13/cobra on 8-Jul-2017
Loading

0 comments on commit 1e9d984

Please sign in to comment.