package main import ( "fmt" "github.com/jnovack/flag" log "github.com/sirupsen/logrus" // "strings" // "strconv" // "time" "os" "bufio" // "github.com/mmcloughlin/geohash" // "github.com/tzneal/ham-go/dxcc" "github.com/denzs/wsjtx_dashboards/shared/wsjtx" ) var station string var pathin string var pathout string var trace bool func usage() { fmt.Printf("Usage of %s:\n", os.Args[0]) flag.PrintDefaults() } func init() { flag.StringVar(&pathin, "in", "", "path to wsjt-x ALL.txt") flag.StringVar(&pathout, "out", "", "path to csv outfile") flag.StringVar(&station, "station", "localstation", "your callsign or wsjtx instance identifier") flag.BoolVar(&trace, "trace", false, "log every line... yes really ;)") flag.Parse() if pathin == "" || pathout == "" { usage() os.Exit(1) } formatter := &log.TextFormatter{ FullTimestamp: true, } log.SetFormatter(formatter) if trace { log.SetLevel(log.TraceLevel) log.Info("trace logging enabled") } else { log.Info("normal logging enabled") } } func main(){ _ , err := os.Stat(pathout) if !os.IsNotExist(err) { log.Fatalf("file %s already exists..", pathout) } fileout, err := os.OpenFile(pathout,os.O_CREATE|os.O_RDWR, 0666) if err != nil { log.Fatal(err) } writer := bufio.NewWriter(fileout) filein, err := os.Open(pathin) if err != nil { log.Fatal(err) } lines := bufio.NewScanner(filein) counter := 0 for lines.Scan() { result, parsed := wsjtx.ScanLine(lines.Text()) if !parsed { continue } counter++ if counter % 1000000 == 0 { log.Infof("%d lines parsed..", counter) } _, err := writer.WriteString(fmt.Sprintf("\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%d\",\"%d\",\n", result.Timestamp.Format("2006-01-02 15:04:05"), station, result.Call, result.Band, result.Ent.Continent, result.Mode, result.Ent.Entity, result.GeoHash, result.Signal, result.Rx)) if err != nil { log.Warn(err) } } writer.Flush() fileout.Close() filein.Close() log.Info("done..") }