2019-11-07 22:16:09 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bufio"
|
|
|
|
"encoding/csv"
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
2019-11-07 22:50:52 +00:00
|
|
|
"html/template"
|
2019-11-07 22:16:09 +00:00
|
|
|
"io"
|
2019-11-08 12:33:46 +00:00
|
|
|
"log"
|
2019-11-07 22:16:09 +00:00
|
|
|
"os"
|
2019-11-08 12:33:46 +00:00
|
|
|
"strings"
|
2019-11-07 22:16:09 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
var file = flag.String("file", "", "File to import")
|
2019-11-08 12:33:46 +00:00
|
|
|
var output = flag.String("output", "", "File to generate")
|
|
|
|
//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 columnDescription = flag.Int("columnDescription", -1, "Column number with a descriptive name or similar")
|
2019-11-07 22:16:09 +00:00
|
|
|
flag.Parse()
|
|
|
|
|
2019-11-08 12:33:46 +00:00
|
|
|
if _, err := os.Stat(*file); os.IsNotExist(err) || *output == "" {
|
2019-11-07 22:16:09 +00:00
|
|
|
flag.Usage()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-11-08 12:33:46 +00:00
|
|
|
fmt.Println("Analyzing " + *file + "...")
|
|
|
|
readCsvFile(*file, *output)
|
2019-11-07 22:16:09 +00:00
|
|
|
}
|
|
|
|
|
2019-11-08 12:33:46 +00:00
|
|
|
func readCsvFile(input string, output string) {
|
|
|
|
csvFile, _ := os.Open(input)
|
|
|
|
reader := csv.NewReader(bufio.NewReader(csvFile))
|
2019-11-07 22:16:09 +00:00
|
|
|
|
2019-11-07 22:50:52 +00:00
|
|
|
type JobDetails struct {
|
2019-11-08 12:33:46 +00:00
|
|
|
Id int
|
|
|
|
Name string
|
|
|
|
Type string
|
|
|
|
Provider string
|
|
|
|
Start []string
|
|
|
|
End []string
|
2019-11-07 22:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type ViewData struct {
|
|
|
|
Jobs []JobDetails
|
|
|
|
}
|
|
|
|
|
|
|
|
var data ViewData
|
|
|
|
|
2019-11-08 12:33:46 +00:00
|
|
|
id := 0
|
2019-11-07 22:16:09 +00:00
|
|
|
for {
|
2019-11-08 12:33:46 +00:00
|
|
|
row, err := reader.Read()
|
2019-11-07 22:16:09 +00:00
|
|
|
if err == io.EOF {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
2019-11-08 12:33:46 +00:00
|
|
|
id++
|
2019-11-07 22:50:52 +00:00
|
|
|
job := JobDetails{
|
2019-11-08 12:33:46 +00:00
|
|
|
Id: id,
|
|
|
|
Name: row[1],
|
|
|
|
Type: row[2],
|
|
|
|
Provider: row[0],
|
|
|
|
Start: strings.Split(row[3], ","),
|
|
|
|
End: strings.Split(row[4], ","),
|
2019-11-07 22:16:09 +00:00
|
|
|
}
|
2019-11-07 22:50:52 +00:00
|
|
|
|
|
|
|
data.Jobs = append(data.Jobs, job)
|
|
|
|
}
|
2019-11-08 12:33:46 +00:00
|
|
|
fmt.Println("Scanning done.")
|
2019-11-07 22:50:52 +00:00
|
|
|
|
2019-11-08 12:33:46 +00:00
|
|
|
fmt.Println("Creating template...")
|
2019-11-07 22:50:52 +00:00
|
|
|
tpl, err := template.ParseFiles("template.html")
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
2019-11-07 22:16:09 +00:00
|
|
|
}
|
2019-11-08 12:33:46 +00:00
|
|
|
|
|
|
|
outputFile, err := os.Create(output)
|
|
|
|
if err != nil {
|
|
|
|
log.Println("create file: ", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
err = tpl.Execute(outputFile, data)
|
|
|
|
if err != nil {
|
|
|
|
log.Print("execute: ", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
outputFile.Close()
|
|
|
|
fmt.Println("Generated " + output)
|
2019-11-07 22:16:09 +00:00
|
|
|
}
|