diff --git a/forecast/print.go b/forecast/print.go index 09309ff..fe9cdef 100644 --- a/forecast/print.go +++ b/forecast/print.go @@ -1,6 +1,7 @@ package forecast import ( + "bytes" "fmt" "math" "strings" @@ -75,6 +76,16 @@ func epochFormatTime(seconds int64) string { return epochTime.Format("3:04pm MST") } +func epochFormatHour(seconds int64) string { + epochTime := time.Unix(0, seconds*int64(time.Second)) + s := epochTime.Format("3pm") + s = s[:len(s)-1] + if len(s) == 2 { + s += " " + } + return s +} + func getIcon(iconStr string) (icon string, err error) { color := "blue" // steralize the icon string name @@ -220,7 +231,38 @@ func PrintCurrent(forecast Forecast, geolocation geocode.Geocode, ignoreAlerts b } } - return printCommon(forecast.Currently, unitsFormat) + if err := printCommon(forecast.Currently, unitsFormat); err != nil { + return err + } + + if forecast.Hourly.Summary != "" { + fmt.Printf("%s\n\n", forecast.Hourly.Summary) + + var ticks = []rune(" ▁▂▃▄▅▆▇█") + rainForecast, showRain := &bytes.Buffer{}, false + for i := 0; i < 16; i++ { + p := forecast.Hourly.Data[i].PrecipProbability + t := int(p*float64(len(ticks)-2)) + 1 + if p == 0 { + t = 0 + } else { + showRain = true + } + rainForecast.WriteRune(ticks[t]) + rainForecast.WriteRune(ticks[t]) + rainForecast.WriteRune(' ') + } + if showRain { + fmt.Printf("Rain chance: %s\n", rainForecast) + fmt.Printf(" ") + for i := 0; i < 4; i++ { + fmt.Printf("%s ", epochFormatHour(forecast.Hourly.Data[i*4].Time)) + } + fmt.Printf("\n\n") + } + } + + return nil } // PrintDaily pretty prints the daily forecast data. diff --git a/main.go b/main.go index 1e92839..d648963 100644 --- a/main.go +++ b/main.go @@ -23,6 +23,7 @@ var ( days int ignoreAlerts bool hideIcon bool + noForecast bool server string vrsn bool client bool @@ -50,6 +51,7 @@ func init() { flag.IntVar(&days, "d", 0, "No. of days to get forecast (shorthand)") flag.BoolVar(&ignoreAlerts, "ignore-alerts", false, "Ignore alerts in weather output") flag.BoolVar(&hideIcon, "hide-icon", false, "Hide the weather icons from being output") + flag.BoolVar(&noForecast, "no-forecast", false, "Hide the forecast for the next 16 hourse") flag.Usage = func() { flag.PrintDefaults() @@ -108,7 +110,10 @@ func main() { Latitude: geo.Latitude, Longitude: geo.Longitude, Units: units, - Exclude: []string{"hourly", "minutely"}, + Exclude: []string{"minutely"}, + } + if noForecast { + data.Exclude = append(data.Exclude, "hourly") } fc, err := forecast.Get(fmt.Sprintf("%s/forecast", server), data)