示例#1
0
文件: main.go 项目: toomore/twsestock
func main() {
	app := cli.NewApp()
	app.Name = "twsedaily"
	app.Usage = "Get daily data and into DB."
	app.Flags = []cli.Flag{
		cli.StringFlag{
			Name:  "twsecate",
			Value: "",
			Usage: "twsecate no",
		},
		cli.StringFlag{
			Name:  "otccate",
			Value: "",
			Usage: "otccate no",
		},
		cli.BoolFlag{
			Name:  "flushcache",
			Usage: "clear cache",
		},
		cli.BoolFlag{
			Name:  "updatefilter",
			Usage: "update filter",
		},
	}
	app.Action = func(c *cli.Context) {
		if c.NumFlags() == 0 {
			cli.ShowAppHelp(c)
			os.Exit(0)
		}
		flushcache = c.Bool("flushcache")
		otccate = c.String("otccate")
		twsecate = c.String("twsecate")
		updateFilter = c.Bool("updatefilter")
	}
	app.Run(os.Args)

	if flushcache {
		temppath := utils.GetOSRamdiskPath()
		utils.NewHTTPCache(temppath, "utf8").FlushAll()
		log.Println("Clear cache", temppath)
	}

	if updateFilter {
		updateFilterInfo()
	}

	recentlyOpened := tradingdays.FindRecentlyOpened(time.Now())
	dailyreportdb := tdb.NewDailyReportDB()
	defer dailyreportdb.Close()

	stockList := makeStockList(twsecate, otccate, recentlyOpened)

	wg.Add(len(stockList))
	for _, stock := range stockList {
		go func(stock *twse.Data, recentlyOpened time.Time) {
			defer wg.Done()
			runtime.Gosched()
			for i, result := range doCheck(stock) {
				if result {
					lastdateList := stock.GetDateList()
					if _, err := dailyreportdb.InsertRecode(stock.No, filter.AllList[i].No(), lastdateList[len(lastdateList)-1].Add(time.Duration(8)*time.Hour)); err == nil {
						log.Println(stock.No, filter.AllList[i])
					} else {
						log.Println("InsertRecode Error", stock.No, i, err)
					}
				}
			}
		}(stock, recentlyOpened)
	}
	wg.Wait()
}
示例#2
0
func init() {
	hCache = utils.NewHTTPCache(utils.GetOSRamdiskPath(), "cp950")
}
示例#3
0
文件: main.go 项目: 668Jerry/gogrs
	-flushall
		Clear cache.

*/
package main

import (
	"flag"
	"log"

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

var hCache = utils.NewHTTPCache(utils.GetOSRamdiskPath(), "utf8")
var flushall = flag.Bool("flushall", false, "Clear cache.")

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()
}

func main() {