Skip to content

Commit

Permalink
Added option to skip csv headers
Browse files Browse the repository at this point in the history
  • Loading branch information
krishnaprasadmg committed Mar 7, 2018
1 parent 8935cf4 commit 6c91d5f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# csvToCamt
Convert CSV correction files to CAMT format

Get binaries from [release page](https://github.com/krishnaprasadmg/csvToCamt/releases/tag/v0.1.3)
Get binaries from [release page](https://github.com/krishnaprasadmg/csvToCamt/releases)

# Example

Expand All @@ -10,3 +10,5 @@ Execute the command with config file (see [sample](config.yaml)) and CSV correct
```
$./csvToCamt -c config.yaml q3.csv q4.csv
```

Optionally use the `-s` flag to skip the headers from CSV files (If the CSVs have headers)
4 changes: 3 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ func init() {

func main() {
var configFile string
var skipHeader bool
flag.StringVar(&configFile, "c", "", "Config file to use, see config.yaml for example")
flag.BoolVar(&skipHeader, "s", false, "Skip CSV header lines, off by default")
flag.Parse()

if configFile == "" || len(flag.Args()) == 0 {
Expand All @@ -29,7 +31,7 @@ func main() {

utils.ParseConfigFile(configFile)

investorData := utils.LoadInvestors(flag.Args())
investorData := utils.LoadInvestors(flag.Args(), skipHeader)
transactionData, totalAmount := utils.BuildTransactions(investorData)

camtDoc := utils.NewCamtDocument()
Expand Down
8 changes: 7 additions & 1 deletion utils/investor.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type Investor struct {
amount float64
}

func LoadInvestors(files []string) []Investor {
func LoadInvestors(files []string, skipHeader bool) []Investor {
var amount float64
investors := make([]Investor, 0)

Expand All @@ -26,13 +26,19 @@ func LoadInvestors(files []string) []Investor {
PanicOnError(err)
defer investorFile.Close()

line := 0
reader := csv.NewReader(investorFile)
reader.Comma = ';'
reader.FieldsPerRecord = 3

for {
line++
record, err := reader.Read()

if line == 1 && skipHeader {
continue
}

if err == io.EOF {
break
} else if err != nil {
Expand Down

0 comments on commit 6c91d5f

Please sign in to comment.