-
Notifications
You must be signed in to change notification settings - Fork 1
/
table_weatherkit_hourly_forecast.go
161 lines (158 loc) · 5.21 KB
/
table_weatherkit_hourly_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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
package weatherkit
import (
"context"
"github.com/turbot/steampipe-plugin-sdk/v3/grpc/proto"
"github.com/turbot/steampipe-plugin-sdk/v3/plugin"
"github.com/turbot/steampipe-plugin-sdk/v3/plugin/transform"
)
func tableWeatherKitHourlyForecast() *plugin.Table {
return &plugin.Table{
Name: "weatherkit_hourly_forecast",
Description: "WeatherKit Hourly Forecast.",
List: &plugin.ListConfig{
KeyColumns: plugin.AllColumns([]string{"latitude", "longitude"}),
Hydrate: listHourlyForecast,
},
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: "cloud_cover",
Type: proto.ColumnType_DOUBLE,
Description: "The percentage of the sky covered with clouds during the period, from 0 to 1.",
},
{
Name: "condition_code",
Type: proto.ColumnType_STRING,
Description: "An enumeration value indicating the condition at the time.",
},
{
Name: "daylight",
Type: proto.ColumnType_BOOL,
Description: "Indicates whether the hour starts during the day or night.",
},
{
Name: "forecast_start",
Type: proto.ColumnType_TIMESTAMP,
Description: "The starting date and time of the forecast.",
},
{
Name: "humidity",
Type: proto.ColumnType_DOUBLE,
Description: "The relative humidity at the start of the hour, from 0 to 1.",
},
{
Name: "precipitation_chance",
Type: proto.ColumnType_DOUBLE,
Description: "The chance of precipitation forecasted to occur during the hour, from 0 to 1.",
},
{
Name: "precipitation_type",
Type: proto.ColumnType_STRING,
Description: "The type of precipitation forecasted to occur during the period.",
},
{
Name: "pressure",
Type: proto.ColumnType_DOUBLE,
Description: "The sea-level air pressure, in millibars.",
},
{
Name: "pressure_trend",
Type: proto.ColumnType_STRING,
Description: "The direction of change of the sea-level air pressure.",
},
{
Name: "snowfall_intensity",
Type: proto.ColumnType_DOUBLE,
Description: "The rate at which snow crystals are falling, in millimeters per hour.",
},
{
Name: "temperature",
Type: proto.ColumnType_DOUBLE,
Description: "The temperature at the start of the hour, in degrees Celsius.",
},
{
Name: "temperature_apparent",
Type: proto.ColumnType_DOUBLE,
Description: "The feels-like temperature when considering wind and humidity, at the start of the hour, in degrees Celsius.",
},
{
Name: "temperature_dew_point",
Type: proto.ColumnType_DOUBLE,
Description: "The temperature at which relative humidity is 100% at the top of the hour, in degrees Celsius.",
},
{
Name: "uv_index",
Type: proto.ColumnType_INT,
Description: "The level of ultraviolet radiation at the start of the hour.",
},
{
Name: "visibility",
Type: proto.ColumnType_DOUBLE,
Description: "The distance at which terrain is visible at the start of the hour, in meters.",
},
{
Name: "wind_direction",
Type: proto.ColumnType_INT,
Description: "The direction of the wind at the start of the hour, in degrees.",
},
{
Name: "wind_gust",
Type: proto.ColumnType_DOUBLE,
Description: "The maximum wind gust speed during the hour, in kilometers per hour.",
},
{
Name: "wind_speed",
Type: proto.ColumnType_DOUBLE,
Description: "The wind speed at the start of the hour, in kilometers per hour.",
},
{
Name: "precipitation_amount",
Type: proto.ColumnType_DOUBLE,
Description: "The amount of precipitation forecasted to occur during period, in millimeters.",
},
{
Name: "metadata",
Type: proto.ColumnType_JSON,
Description: "Descriptive information about the weather data.",
},
},
}
}
func listHourlyForecast(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.HourlyForecast(ctx, latitude, longitude)
type Row struct {
HourWeatherConditions
Metadata WeatherMetadata `json:"metadata,omitempty"`
}
for _, hour := range weather.HourlyForecast.Hours {
row := Row{
HourWeatherConditions: hour,
Metadata: weather.HourlyForecast.Metadata,
}
d.StreamListItem(ctx, row)
if plugin.IsCancelled(ctx) {
logger.Trace("CANCELLED!")
return nil, nil
}
}
return nil, nil
}