weather-cli/cmd/render.go

45 lines
1.6 KiB
Go
Raw Normal View History

2022-07-26 22:18:41 -04:00
package main
import "fmt"
// Prints saved weather data to the terminal
2022-08-02 23:26:28 -04:00
func printWeather(app *Application) {
2022-07-26 22:18:41 -04:00
var unitStr string
if app.Config.Units == "imperial" {
unitStr = "Farhenheit/mph"
} else {
2022-08-09 01:18:11 -04:00
unitStr = "Celsius/mps"
2022-07-26 22:18:41 -04:00
}
fmt.Println("\nNote! A value of 0 or 0.00 indicates the data is not available at this time.")
fmt.Printf("Units: %s (%s)\n\n", app.Config.Units, unitStr)
2022-08-06 22:16:56 -04:00
fmt.Printf("Current temperature: %.2f\n", app.Forecast.Weather.Temp)
fmt.Printf("Feels like: %.2f\n", app.Forecast.Weather.FeelsLike)
fmt.Printf("High: %.2f\n", app.Forecast.Weather.HighTemp)
fmt.Printf("Low: %.2f\n", app.Forecast.Weather.LowTemp)
fmt.Printf("Pressure (hPa): %d\n", app.Forecast.Weather.Pressure)
fmt.Printf("Humidity (%%): %d\n", app.Forecast.Weather.Humidity)
2022-07-26 22:18:41 -04:00
fmt.Printf("Wind speed: %.2f\n", app.Forecast.Wind.Speed)
fmt.Printf("Gust: %.2f\n", app.Forecast.Wind.Gust)
}
2022-08-06 22:16:56 -04:00
// Prints saved historical data to the terminal
func printHistorical(app *Application) {
var unitStr string
if app.Config.Units == "imperial" {
unitStr = "Farhenheit/mph"
} else {
2022-08-09 01:18:11 -04:00
unitStr = "Celsius/mps"
2022-08-06 22:16:56 -04:00
}
fmt.Println("\nNote! A value of 0 or 0.00 indicates the data is not available at this time.")
fmt.Printf("Units: %s (%s)\n\n", app.Config.Units, unitStr)
fmt.Printf("Temperature: %.2f\n", app.HistoricalForecast.Temp)
fmt.Printf("Felt like: %.2f\n", app.HistoricalForecast.FeelsLike)
fmt.Printf("Pressure (hPa): %d\n", app.HistoricalForecast.Pressure)
fmt.Printf("Humidity (%%): %d\n", app.HistoricalForecast.Humidity)
fmt.Printf("Wind speed: %.2f\n", app.HistoricalForecast.Speed)
}