parent
7e9647b1ae
commit
b8a82b0050
|
@ -29,9 +29,15 @@ func New() *NwsClient {
|
|||
func (c *NwsClient) CoordinatesToPoint(lat float64, lon float64) (Point, error) {
|
||||
var p Point
|
||||
_, err := c.restClient.R().SetResult(&p).Get(fmt.Sprintf("points/%f,%f", lat, lon))
|
||||
p.Lat = lat
|
||||
p.Lon = lon
|
||||
return p, err
|
||||
}
|
||||
|
||||
func (p Point) GetWebURL() string {
|
||||
return fmt.Sprintf("https://forecast.weather.gov/MapClick.php?lat=%f&lon=%f", p.Lat, p.Lon)
|
||||
}
|
||||
|
||||
func (c *NwsClient) GetHourlyForecast(p Point) (HourlyProps, error) {
|
||||
var data struct {
|
||||
Properties HourlyProps `json:"properties"`
|
||||
|
@ -45,6 +51,19 @@ func (c *NwsClient) GetHourlyForecast(p Point) (HourlyProps, error) {
|
|||
return data.Properties, nil
|
||||
}
|
||||
|
||||
func (c *NwsClient) GetDailyForecast(p Point) (DailyProps, error) {
|
||||
var data struct {
|
||||
Properties DailyProps `json:"properties"`
|
||||
}
|
||||
_, err := util.CheckSuccess(c.restClient.R().SetResult(&data).
|
||||
Get(removeBase(p.Properties.Forecast)))
|
||||
if err != nil {
|
||||
return DailyProps{}, nil
|
||||
}
|
||||
|
||||
return data.Properties, nil
|
||||
}
|
||||
|
||||
func (p HourlyProps) GetHighLow(hours int) (high int, low int) {
|
||||
if hours > len(p.Periods) {
|
||||
hours = len(p.Periods)
|
||||
|
|
|
@ -23,6 +23,8 @@ type PointProps struct {
|
|||
type Point struct {
|
||||
ID string `json:"id"`
|
||||
Properties PointProps `json:"properties"`
|
||||
Lat float64
|
||||
Lon float64
|
||||
}
|
||||
|
||||
type HourlyPeriod struct {
|
||||
|
@ -42,6 +44,31 @@ type HourlyProps struct {
|
|||
Periods []HourlyPeriod `json:"periods"`
|
||||
}
|
||||
|
||||
type DailyPeriod struct {
|
||||
Number int `json:"number,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
StartTime string `json:"startTime,omitempty"`
|
||||
EndTime string `json:"endTime,omitempty"`
|
||||
IsDaytime bool `json:"isDaytime,omitempty"`
|
||||
Temperature int `json:"temperature,omitempty"`
|
||||
TemperatureUnit string `json:"temperatureUnit,omitempty"`
|
||||
TemperatureTrend string `json:"temperatureTrend,omitempty"`
|
||||
ProbabilityOfPrecipitation UnitValue[int] `json:"probabilityOfPrecipitation,omitempty"`
|
||||
Dewpoint UnitValue[float64] `json:"dewpoint,omitempty"`
|
||||
RelativeHumidity UnitValue[int] `json:"relativeHumidity,omitempty"`
|
||||
WindSpeed string `json:"windSpeed,omitempty"`
|
||||
WindDirection string `json:"windDirection,omitempty"`
|
||||
Icon string `json:"icon,omitempty"`
|
||||
ShortForecast string `json:"shortForecast,omitempty"`
|
||||
DetailedForecast string `json:"detailedForecast,omitempty"`
|
||||
}
|
||||
|
||||
type DailyProps struct {
|
||||
Updated time.Time `json:"updated"`
|
||||
Units string `json:"units"`
|
||||
Periods []DailyPeriod `json:"periods"`
|
||||
}
|
||||
|
||||
type Observations struct {
|
||||
Timestamp time.Time `json:"timestamp"`
|
||||
Temperature UnitValue[float64] `json:"temperature"`
|
||||
|
|
Loading…
Reference in New Issue