summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--weather.go56
1 files changed, 18 insertions, 38 deletions
diff --git a/weather.go b/weather.go
index 56d6bdf..be227cb 100644
--- a/weather.go
+++ b/weather.go
@@ -16,21 +16,6 @@ import (
const defid = "310118"
-var wkey = map[string]string{
- "f": "Feels Like Temperature",
- "h": "Humidity",
- "p": "Pressure",
- "t": "Temperature",
- "v": "Visibility",
- "wg": "Wind Gust",
- "ws": "Wind Speed",
- "pp": "Precipitaton Probability",
- "uv": "Max UV Index",
- "wd": "Wind Direction",
- "wt": "Weather Type",
- "AQIndex": "Air Quality",
-}
-
type Response struct {
BestFcst struct {
Forecast struct {
@@ -58,18 +43,18 @@ type Day struct {
}
type WeatherParams struct {
- AQIndex float64
- F float64
- H float64
- P float64
- PP float64
- UV float64
- T float64
- V float64
- WD string
- WG float64
- WS float64
- WT float64
+ AQIndex int // Air Quality
+ F float64 // Feels Like Temperature
+ H int // Humidity
+ P int // Pressure
+ PP int // Precipitation Probability
+ UV int // Max UV Index
+ T float64 // Temperature
+ V int // Visibility
+ WD string // Wind Direction
+ WG float64 // Wind Gust
+ WS float64 // Wind Speed
+ WT int // Weather Type
}
func main() {
@@ -97,21 +82,16 @@ func main() {
for _, d := range r.BestFcst.Forecast.Location.Days {
fmt.Printf("-----------------------------\n")
- fmt.Printf("Date: %v\n", d.Date)
- fmt.Printf("\nDay weather:\n")
- prettyWeather(d.DayValues.WeatherParameters)
- fmt.Printf("\nNight weather:\n")
- prettyWeather(d.NightValues.WeatherParameters)
+ fmt.Printf("%s\n", d.Date)
+ prettyWeather("Day ", d.DayValues.WeatherParameters)
+ prettyWeather("Night ", d.NightValues.WeatherParameters)
- fmt.Printf("\nTime steps:\n")
for _, t := range d.TimeSteps.TimeStep {
- fmt.Printf("\nTime: %s\n", t.Time)
- prettyWeather(t.WeatherParameters)
+ prettyWeather(t.Time, t.WeatherParameters)
}
}
}
-func prettyWeather(w WeatherParams) {
- // TODO: Print weather nicely
- fmt.Printf("%+v\n", w)
+func prettyWeather(t string, w WeatherParams) {
+ fmt.Printf("%s Type: %2d, Temp: %4.1f°C, Rain: %2d%%, Wind: %2.1fkph\n", t, w.WT, w.T, w.PP, w.WS)
}