diff --git a/main.go b/main.go index 58fea36..3ef6700 100644 --- a/main.go +++ b/main.go @@ -5,6 +5,7 @@ import ( "encoding/csv" "flag" "fmt" + "html/template" "io" "os" ) @@ -13,30 +14,53 @@ func main() { var file = flag.String("file", "", "File to import") var columnStart = flag.Int("columnStart", -1, "Column number with a start Datetime") var columnEnd = flag.Int("columnEnd", -1, "Column number with a end Datetime") - var descriptiveColumn = flag.Int("columnDescription", -1, "Column number with a descriptive name or similar") + var columnDescription = flag.Int("columnDescription", -1, "Column number with a descriptive name or similar") flag.Parse() - if _, err := os.Stat(*file); os.IsNotExist(err) || *columnStart == -1 || *columnEnd == -1 || *descriptiveColumn == -1 { + if _, err := os.Stat(*file); os.IsNotExist(err) || *columnStart == -1 || *columnEnd == -1 || *columnDescription == -1 { flag.Usage() return } fmt.Println("Scanning file " + *file + "...") - readCsvFile(*file, *columnStart, *columnEnd, *descriptiveColumn) + readCsvFile(*file, *columnStart, *columnEnd, *columnDescription) } -func readCsvFile(csvFile string, columnStart int, columnEnd int, descriptiveColumn int) { +func readCsvFile(csvFile string, columnStart int, columnEnd int, columnDescription int) { f, _ := os.Open(csvFile) r := csv.NewReader(bufio.NewReader(f)) + type JobDetails struct { + Start string + End string + Description string + } + + type ViewData struct { + Jobs []JobDetails + } + + var data ViewData + for { - record, err := r.Read() + row, err := r.Read() if err == io.EOF { break } - for value := range record { - fmt.Printf(" %v\n", record[value]) + job := JobDetails{ + Start: row[columnStart], + End: row[columnEnd], + Description: row[columnDescription], } + + data.Jobs = append(data.Jobs, job) } + + tpl, err := template.ParseFiles("template.html") + if err != nil { + fmt.Println(err) + } + fmt.Printf("%+v\n", data) + tpl.Execute(os.Stdout, data) } diff --git a/template.html b/template.html new file mode 100644 index 0000000..631049c --- /dev/null +++ b/template.html @@ -0,0 +1,9 @@ + +
{{ .Description }} | +