Ejemplo n.º 1
0
func init() {
	var (
		err error
	)
	runtime.GOMAXPROCS(runtime.NumCPU())
	flag.StringVar(&workDir, "o", "", "")
	flag.IntVar(&noOfWorkers, "n", 5, "")
	flag.BoolVar(&sendOnly, "s", false, "")
	flag.BoolVar(&testMode, "tm", false, "")
	flag.StringVar(&exportTypes, "e", "", "")
	flag.Parse()
	workDir, err = filepath.Abs(strings.ToLower(workDir))
	utils.LogErr(err, "Dest folder path")
	if len(workDir) == 0 {
		fmt.Println("Set out forlder path")
		os.Exit(0)
	}

	if runtime.GOOS == "windows" {
		tmpPrefix = `c:\tmp`
	} else {
		tmpPrefix = `/tmp/`
	}
	f, err := os.Create(`ms-expot.log`)
	if err != nil {
		panic(err)
	}
	wr := io.MultiWriter(f, os.Stdout)
	log.SetOutput(wr)
	settings = &config{workDir: workDir,
		noOfWorkers: noOfWorkers,
		tmpPrefix:   tmpPrefix,
		sendOnly:    sendOnly,
		exports:     exportTypes,
		testMode:    testMode}

	exports = map[string]exportFunc{
		"gratka": exportGratka,
		"otodom": exportGratka}

}
Ejemplo n.º 2
0
func main() {
	var (
		err      error
		offersNo int
		types    []string
	)
	if len(settings.exports) == 0 {
		types = allExportsTypes
	} else {
		types = strings.Split(settings.exports, ",")
		for _, typ := range types {
			if _, ok := exports[typ]; !ok {
				log.Fatalf("Unsupported export name %s", typ)
			}
		}
	}
	setCredentials("db")
	startTime := time.Now()
	// validate paths, remove / create dirctory
	if err = validPaths(settings); err != nil {
		utils.LogErrf(err, "Settings paths")
	}

	if !settings.sendOnly {
		// dump to XML
		log.Printf("Start getting data from DB\n")
		offersNo, err = dumpAsXML(settings)
		utils.LogErr(err, "Dump XML")
		log.Printf("Got %d offers from DB (in %v)\n", offersNo, time.Now().Sub(startTime))
	}

	for _, name := range types {
		if err = exports[name](name, settings); err != nil {
			utils.LogErrf(err, "Error durring process %s", name)
		}
	}
	log.Printf("All done in %v\n", time.Now().Sub(startTime))
}
Ejemplo n.º 3
0
func (d *DB) CloseRows(rows *sql.Rows) {
	utils.LogErr(rows.Close(), "Close rows")
}
Ejemplo n.º 4
0
func (d *DB) Query(query string) (rows *sql.Rows, err error) {
	rows, err = d.Db.Query(query)
	utils.LogErr(err, "Query")
	return
}
Ejemplo n.º 5
0
func (d *DB) Close() (err error) {
	err = d.Db.Close()
	utils.LogErr(err, "Close db")
	return
}