You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

100 lines
2.3 KiB

package main
import (
"flag"
"fmt"
"log"
"os"
"src.wolkict.net/cdr"
)
var (
csvFile = flag.String("csv", "", "use this call detail record CSV file")
pricesFile = flag.String("prices", "", "use this pricing CSV file")
priceExec = flag.Bool("execute", false, "price each CDR according to the prices file")
debugImport = flag.Bool("debugImport", false, "show extra debugging info for import")
debug = flag.Bool("debug", false, "show extra debugging info")
)
func usage() {
fmt.Println("Usage: cdrtool -csv <file.csv> [-prices <file.csv>] [-debug] [-execute]")
flag.PrintDefaults()
}
func main() {
flag.Parse()
if *csvFile == "" {
usage()
log.Fatalf("mandatory -csv not set")
}
if _, err := os.Open(*csvFile); err != nil {
log.Fatalf("cannot access CSV %q: %v", *csvFile, err)
}
if _, err := os.Open(*pricesFile); err != nil {
log.Printf("[warning] cannot access prices file %q", *pricesFile)
}
imported, err := cdr.ImportCSV(*csvFile)
if err != nil {
log.Fatalf("importing CSV failed: %v", err)
}
if *debug {
log.Printf("importing CDR CSV %q succeeded", *csvFile)
}
importedPrices, err := cdr.ImportPricesFile(*pricesFile)
if err != nil && *priceExec {
log.Fatalf("importing prices CSV %q failed: %v", *pricesFile, err)
}
if *debugImport {
if err != nil {
log.Printf("[warning] importing prices CSV %q failed: %v", *pricesFile, err)
} else {
log.Printf("importing prices CSV %q succeeded", *pricesFile)
}
}
if *debugImport {
for _, i := range imported {
fmt.Printf("l: %+v\n", i)
}
for _, i := range importedPrices {
fmt.Printf("p: %+v\n", i)
}
}
if *priceExec {
texts, err := cdr.CombineTextCDRs(imported, importedPrices)
if err != nil {
log.Fatalf("combining text CDRs with prices failed: %v", err)
}
data, err := cdr.CombineDataCDRs(imported, importedPrices)
if err != nil {
log.Fatalf("combining data CDRs with prices failed: %v", err)
}
calls, err := cdr.CombineCallCDRs(imported, importedPrices)
if err != nil {
log.Fatalf("combining call CDRs with prices failed: %v", err)
}
if *debug {
for _, t := range texts {
fmt.Printf("t: %+v\n", t)
}
for _, d := range data {
fmt.Printf("d: %+v\n", d)
}
for _, c := range calls {
fmt.Printf("c: %+v\n", c)
}
}
}
}