Skip to content

Commit

Permalink
for CO2 and O2 sensor
Browse files Browse the repository at this point in the history
  • Loading branch information
tkschmidt committed Aug 28, 2013
0 parents commit 8529e3c
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions batConvert.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package main

import (
"bufio"
"fmt"
"log"
"os"
"path/filepath"
"strings"
)

func visit(path string, f os.FileInfo, err error) error {
if strings.Contains(path, "dat") {
fmt.Printf(path + "\n")
getConvert(path, f)
}
//fmt.Printf("Visited: %s\n", path)
return nil
}

func getConvert(path string, f os.FileInfo) {
file, _ := os.Open(path)
scanner := bufio.NewScanner(file)
var firstLine bool = true
var lineContext string = ""
fileb, _ := os.Create(strings.Replace(f.Name(), ".dat", "", -1) + ".csv")
writer := bufio.NewWriter(fileb)
for scanner.Scan() {
if firstLine == false {
lineContext = strings.Replace(strings.Replace(scanner.Text(), " ", "", -1), "2013", "2013 ", -1)
writer.WriteString(lineContext + "\n")
} else {
firstLine = false
}
}

if err := scanner.Err(); err != nil {
log.Fatal(err)
}
writer.Flush()
file.Close()
}

func main() {
err := filepath.Walk(".", visit)
fmt.Printf("filepath.Walk() returned %v\n", err)

}

0 comments on commit 8529e3c

Please sign in to comment.