1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- package main
- import (
- "bufio"
- "compress/gzip"
- "encoding/binary"
- "flag"
- "fmt"
- "io"
- "log"
- "os"
- "strings"
- "tickserver/server/market"
- )
- func main() {
- flag.Parse()
- n := flag.NArg()
- if n != 2 {
- log.Println("number of parameter must be 2", n)
- return
- }
- file0 := flag.Arg(0)
- f0, _ := os.Open(file0)
- file1 := flag.Arg(1)
- w, err := os.OpenFile(file1, os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0666)
- if err != nil {
- return
- }
- defer w.Close()
- gw := gzip.NewWriter(w)
- bw := bufio.NewWriter(gw)
- var candle market.Candle
- buf := bufio.NewReader(f0)
- for {
- line, err := buf.ReadString('\n')
- line = strings.TrimSpace(line)
- if err != nil {
- if err != io.EOF {
- log.Println(err)
- }
- break
- }
- var year, month, day, hour, minute, second int
- _, err = fmt.Sscanf(line, "%04d%02d%02d %02d:%02d:%02d {%d %f %f %f %f %f %f}", &year, &month, &day, &hour, &minute, &second, &candle.Timestamp, &candle.Open, &candle.High, &candle.Low, &candle.Close, &candle.RealVolums, &candle.TickVolums)
- if err != nil {
- log.Println(line, err)
- break
- }
- log.Println(candle)
- binary.Write(bw, binary.LittleEndian, candle)
- }
- bw.Flush()
- gw.Close()
- }
|