-
Notifications
You must be signed in to change notification settings - Fork 1
/
table_weatherkit_next_hour_forecast.go
95 lines (92 loc) · 2.94 KB
/
table_weatherkit_next_hour_forecast.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package weatherkit
import (
"context"
"github.com/turbot/steampipe-plugin-sdk/v4/grpc/proto"
"github.com/turbot/steampipe-plugin-sdk/v4/plugin"
"github.com/turbot/steampipe-plugin-sdk/v4/plugin/transform"
)
func tableWeatherKitNextHourForecast() *plugin.Table {
return &plugin.Table{
Name: "weatherkit_next_hour_forecast",
Description: "WeatherKit Next Hour Forecast.",
List: &plugin.ListConfig{
KeyColumns: plugin.AllColumns([]string{"latitude", "longitude"}),
Hydrate: listNextHourForecast,
},
Columns: []*plugin.Column{
{
Name: "latitude",
Type: proto.ColumnType_STRING,
Description: "A numeric value indicating the latitude of the coordinate between -90 and 90.",
Transform: transform.FromQual("latitude"),
},
{
Name: "longitude",
Type: proto.ColumnType_STRING,
Description: "A numeric value indicating the longitude of the coordinate between -180 and 180.",
Transform: transform.FromQual("longitude"),
},
{
Name: "forecast_end",
Type: proto.ColumnType_TIMESTAMP,
Description: "The time the forecast ends.",
},
{
Name: "forecast_start",
Type: proto.ColumnType_TIMESTAMP,
Description: "The time the forecast starts.",
},
{
Name: "precipitation_chance",
Type: proto.ColumnType_DOUBLE,
Description: "The probability of precipitation during this minute.",
},
{
Name: "precipitation_intensity",
Type: proto.ColumnType_DOUBLE,
Description: "The precipitation intensity in millimeters per hour.",
},
{
Name: "start_time",
Type: proto.ColumnType_TIMESTAMP,
Description: "The start time of the minute.",
},
{
Name: "metadata",
Type: proto.ColumnType_JSON,
Description: "Descriptive information about the weather data.",
},
},
}
}
func listNextHourForecast(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) {
logger := plugin.Logger(ctx)
service, err := connect(ctx, d)
if err != nil {
logger.Error("Invalid credentials.")
return nil, err
}
latitude := d.KeyColumnQuals["latitude"].GetStringValue()
longitude := d.KeyColumnQuals["longitude"].GetStringValue()
weather, _ := service.NextHourForecast(ctx, latitude, longitude)
type Row struct {
ForecastMinute
ForecastEnd string `json:"forecastEnd,omitempty"`
ForecastStart string `json:"forecastStart,omitempty"`
Metadata WeatherMetadata `json:"metadata,omitempty"`
}
for _, minute := range weather.NextHourForecast.Minutes {
row := Row{
ForecastMinute: minute,
ForecastEnd: weather.NextHourForecast.ForecastEnd,
ForecastStart: weather.NextHourForecast.ForecastStart,
Metadata: weather.NextHourForecast.Metadata,
}
d.StreamListItem(ctx, row)
if plugin.IsCancelled(ctx) {
logger.Trace("CANCELLED!")
return nil, nil
}
}
return nil, nil
}