|
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"flag"
|
|
|
|
|
"fmt"
|
|
|
|
|
"log"
|
|
|
|
|
"os"
|
|
|
|
|
|
|
|
|
|
"src.wolkict.net/cdr"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var (
|
|
|
|
|
csvFile = flag.String("csv", "", "use this call detail record CSV file")
|
|
|
|
|
validate = flag.Bool("validate", false, "only validate the call detail record CSV, perform no other actions")
|
|
|
|
|
pricesFile = flag.String("prices", "", "use this pricing CSV file")
|
|
|
|
|
priceExec = flag.Bool("execute", false, "price each CDR according to the prices file")
|
|
|
|
|
debug = flag.Bool("debug", false, "show extra debugging")
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func usage() {
|
|
|
|
|
fmt.Println("Usage: cdrtool -csv <file.csv> [-prices <file.csv>] [-validate]")
|
|
|
|
|
flag.PrintDefaults()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
|
|
if *csvFile == "" {
|
|
|
|
|
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 *validate {
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Fatalf("[validate] importing %q failed: %v", *csvFile, err)
|
|
|
|
|
}
|
|
|
|
|
log.Printf("[validate] importing %q succeeded", *csvFile)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Fatalf("importing CSV failed: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
importedPrices, err := cdr.ImportPricesFile(*pricesFile)
|
|
|
|
|
if *validate {
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Fatalf("[validate] importing %q failed: %v", *pricesFile, err)
|
|
|
|
|
}
|
|
|
|
|
log.Printf("[validate] importing %q succeeded", *pricesFile)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Fatalf("importing CSV failed: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if *debug {
|
|
|
|
|
for _, i := range imported {
|
|
|
|
|
fmt.Printf("l: %+v\n", i)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, i := range importedPrices {
|
|
|
|
|
fmt.Printf("p: %+v\n", i)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if *priceExec {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|