-
Notifications
You must be signed in to change notification settings - Fork 0
/
weather.go
47 lines (35 loc) · 836 Bytes
/
weather.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
package main
import (
"context"
"encoding/json"
"flag"
"fmt"
"time"
"github.com/colevoss/go-iem-sdk"
)
func main() {
stationId := flag.String("s", "", "Station to fetch weather for")
flag.Parse()
if *stationId == "" {
fmt.Println("Station (s) arg is required")
return
}
ctx := context.Background()
client := iem.NewClientWithOptions()
now := time.Now()
yesterday := now.AddDate(0, 0, -2)
query := iem.NewWeatherDataQuery()
query.Stations(*stationId)
query.Timezone("America/Chicago")
query.ReportType(3)
query.Data(iem.TempF, iem.TempC, iem.Feel)
query.Start(yesterday)
query.End(yesterday)
data, err := client.Weather().Get(ctx, query)
if err != nil {
panic(err)
}
str, _ := json.MarshalIndent(data, "", " ")
fmt.Println(string(str))
fmt.Printf("Weather Records Count: %d\n", len(data))
}