Skip to content

Commit

Permalink
Add option to print records in Nightscout format
Browse files Browse the repository at this point in the history
  • Loading branch information
ecc1 committed Sep 20, 2018
1 parent 5dc5e95 commit fbb7d23
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions cmd/checkpage/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"encoding/json"
"flag"
"fmt"
"io"
"log"
Expand All @@ -10,8 +11,13 @@ import (
"github.com/ecc1/dexcom"
)

var (
nsFlag = flag.Bool("n", false, "print records in Nightscout format")
)

func main() {
for _, file := range os.Args[1:] {
flag.Parse()
for _, file := range flag.Args() {
f, err := os.Open(file)
if err != nil {
log.Fatal(err)
Expand Down Expand Up @@ -40,7 +46,12 @@ func readRecords(data []byte) {
func printResults(results dexcom.Records) {
e := json.NewEncoder(os.Stdout)
e.SetIndent("", " ")
err := e.Encode(results)
var err error
if *nsFlag {
err = e.Encode(dexcom.NightscoutEntries(results))
} else {
err = e.Encode(results)
}
if err != nil {
log.Fatal(err)
}
Expand Down

0 comments on commit fbb7d23

Please sign in to comment.