ArinDash/apis/openweathermap/currentWeather.go

113 lines
2.9 KiB
Go

package openWeatherMap
import "time"
type CurrentWeather struct {
Base string `json:"base"`
Visibility int `json:"visibility"`
Dt int `json:"dt"`
Timezone int `json:"timezone"`
Id int `json:"id"`
Name string `json:"name"`
Cod int `json:"cod"`
Coordinates Coordinates `json:"coord"`
Weather []Weather `json:"weather"`
Wind Wind `json:"wind"`
Clouds Clouds `json:"clouds"`
Rain Rain `json:"rain"`
Snow Snow `json:"snow"`
Sys Sys `json:"sys"`
Main Main `json:"main"`
ErrorMessage string
}
type Coordinates struct {
Lon float64 `json:"lon"`
Lat float64 `json:"lat"`
}
type Weather struct {
Id int `json:"id"`
Main string `json:"main"`
Description string `json:"description"`
Icon string `json:"icon"`
}
type Wind struct {
Speed float64 `json:"speed"`
Deg float64 `json:"deg"`
}
type Clouds struct {
All int `json:"all"`
}
type Rain struct {
OneH float64 `json:"1h"`
}
type Snow struct {
OneH float64 `json:"1h"`
}
type Sys struct {
Type int `json:"type"`
Id int `json:"id"`
Country string `json:"country"`
Sunrise int64 `json:"sunrise"`
Sunset int64 `json:"sunset"`
}
type Main struct {
Temp float64 `json:"temp"`
FeelsLike float64 `json:"feels_like"`
TempMin float64 `json:"temp_min"`
TempMax float64 `json:"temp_max"`
Pressure int `json:"pressure"`
Humidity int `json:"humidity"`
SeaLevel int `json:"sea_level"`
GrndLevel int `json:"grnd_level"`
}
func (currentWeather *CurrentWeather) CardinalWindDirection() string {
windDeg := currentWeather.Wind.Deg
if windDeg > 11.25 && windDeg <= 33.75 {
return `NNE`
} else if windDeg > 33.75 && windDeg <= 56.25 {
return "NE"
} else if windDeg > 56.25 && windDeg <= 78.75 {
return "ENE"
} else if windDeg > 78.75 && windDeg <= 101.25 {
return "E"
} else if windDeg > 101.25 && windDeg <= 123.75 {
return "ESE"
} else if windDeg > 123.75 && windDeg <= 146.25 {
return "SE"
} else if windDeg > 146.25 && windDeg <= 168.75 {
return "SSE"
} else if windDeg > 168.75 && windDeg <= 191.25 {
return "S"
} else if windDeg > 191.25 && windDeg <= 213.75 {
return "SSW"
} else if windDeg > 213.75 && windDeg <= 236.25 {
return "SW"
} else if windDeg > 236.25 && windDeg <= 258.75 {
return "WSW"
} else if windDeg > 258.75 && windDeg <= 281.25 {
return "W"
} else if windDeg > 281.25 && windDeg <= 303.75 {
return "WNW"
} else if windDeg > 303.75 && windDeg <= 326.25 {
return "NW"
} else if windDeg > 326.25 && windDeg <= 348.75 {
return "NNW"
}
return `N`
}
func (currentWeather *CurrentWeather) IsDayTime() bool {
now := time.Now()
return now.After(time.Unix(currentWeather.Sys.Sunrise, 0)) && now.Before(time.Unix(currentWeather.Sys.Sunset, 0))
}