-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
58 lines (47 loc) · 1.21 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package main
import (
"encoding/csv"
"fmt"
"os"
"github.com/qwerqy/ynab-csv-converter/internal/bank"
)
func main() {
// Input and output file paths
inputFile := "TransactionHistory.csv"
outputFile := "ynab_formatted.csv"
b := bank.NewBank()
// Open the input file
file, err := os.Open(inputFile)
if err != nil {
fmt.Printf("Error opening file: %v\n", err)
return
}
defer file.Close()
// Read the CSV content
reader := csv.NewReader(file)
reader.FieldsPerRecord = -1 // Allow variable-length rows
rows, err := reader.ReadAll()
if err != nil {
fmt.Printf("Error reading CSV: %v\n", err)
return
}
// Create the output file
outFile, err := os.Create(outputFile)
if err != nil {
fmt.Printf("Error creating file: %v\n", err)
return
}
defer outFile.Close()
// Write cleaned data to the new file
writer := csv.NewWriter(outFile)
defer writer.Flush()
// Add YNAB headers
ynabHeaders := []string{"Date", "Payee", "Memo", "Amount"}
if err := writer.Write(ynabHeaders); err != nil {
fmt.Printf("Error writing headers: %v\n", err)
return
}
// Process each row and write to the new file
b.HSBC.Credit.Process(writer, rows)
fmt.Println("Conversion complete. Output saved to:", outputFile)
}