示例#1
0
func main() {
	src := flag.String("source", "", "source CSV file")
	trgt := flag.String("target", "", "target file")
	frmt := flag.String("format", "json", "target file format (json, yaml)")
	codeCol := flag.String("code", "Code", "name of the code column")
	valCol := flag.String("val", "Text Deutsch", "name of the value column")
	flag.Parse()

	if len(*trgt) == 0 {
		os.Stderr.WriteString("target is required\n")
		flag.Usage()
		os.Exit(1)
	}

	if len(*src) == 0 {
		os.Stderr.WriteString("source is required\n")
		flag.Usage()
		os.Exit(1)
	}

	os.Stdout.WriteString(fmt.Sprintf("Opening %s ...\n", *src))
	site := new(config.Site)
	site.Source = *src
	target := new(config.Target)
	target.Code = *codeCol
	target.Val = *valCol
	target.Target = *trgt
	target.Format = *frmt
	site.Targets = append(site.Targets, target)
	c := command.NewImportCommand(site)
	err, errorStrings := c.Exec()
	if err != nil {
		os.Stderr.WriteString(err.Error() + "\n")
		for _, v := range errorStrings {
			os.Stderr.WriteString(v.Msg)
		}
		os.Exit(1)
	}
	os.Stdout.WriteString(fmt.Sprintf("%s written.\n", *trgt))
	return
}
示例#2
0
func (e *HookHandler) ServeHTTP(response http.ResponseWriter, request *http.Request) {
	// TODO: get site from request
	ident := "charity"
	site, err := e.Config.GetSite(ident)
	if err != nil {
		response.WriteHeader(400)
		response.Write([]byte("ERROR\n"))
	}

	go func(site *config.Site) {
		c := command.NewImportCommand(site)
		err, errorStrings := c.Exec()
		if err != nil {
			os.Stderr.WriteString(err.Error() + "\n")
			for _, v := range errorStrings {
				os.Stderr.WriteString(v.Msg)
			}
		}
	}(&site)

	fmt.Fprintf(response, "Fetching strings for site '%s' from source '%s'.\n", ident, site.Source)
}