Skip to content

Commit

Permalink
Add extra features for importing other files
Browse files Browse the repository at this point in the history
Found a csv that is delimited by semi-colon and not a comma
Handle other column headers in csv file
  • Loading branch information
howeyc committed Aug 12, 2015
1 parent 5831d50 commit cf912c0
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/cmd/limport/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os"
"strings"
"time"
"unicode/utf8"

"ledger"

Expand All @@ -24,10 +25,12 @@ func main() {
var ledgerFileName string
var accountSubstring, csvFileName, csvDateFormat string
var negateAmount bool
var fieldDelimiter string

flag.BoolVar(&negateAmount, "neg", false, "Negate amount column value.")
flag.StringVar(&ledgerFileName, "f", "", "Ledger file name (*Required).")
flag.StringVar(&csvDateFormat, "date-format", "01/02/2006", "Date format.")
flag.StringVar(&fieldDelimiter, "delimiter", ",", "Field delimiter.")
flag.Parse()

args := flag.Args()
Expand Down Expand Up @@ -70,6 +73,7 @@ func main() {
allAccounts := ledger.GetBalances(generalLedger, []string{})

csvReader := csv.NewReader(csvFileReader)
csvReader.Comma, _ = utf8.DecodeRuneInString(fieldDelimiter)
csvRecords, _ := csvReader.ReadAll()

classes := make([]bayesian.Class, len(allAccounts))
Expand All @@ -95,8 +99,12 @@ func main() {
dateColumn = fieldIndex
} else if strings.Contains(fieldName, "description") {
payeeColumn = fieldIndex
} else if strings.Contains(fieldName, "payee") {
payeeColumn = fieldIndex
} else if strings.Contains(fieldName, "amount") {
amountColumn = fieldIndex
} else if strings.Contains(fieldName, "expense") {
amountColumn = fieldIndex
}
}

Expand Down

0 comments on commit cf912c0

Please sign in to comment.