package cmd import ( "fmt" "time" "git.sr.ht/~timharek/yr/cmd/internal/ui/table" "github.com/spf13/cobra" ) var todayCmd = &cobra.Command{ Use: "today ", Short: "Get tomorrow's forecasted weather", Args: cobra.MaximumNArgs(1), Run: today, } func init() { rootCmd.AddCommand(todayCmd) } func today(cmd *cobra.Command, args []string) { helper := forecastHelper(cmd, args) f := helper.f if helper.isWeb { openBrowser("https://www.yr.no/en/forecast/hourly-table/%.4f,%.4f?i=0", f) } if helper.isJson { outputJson(f.Forecast) } t := table.New() today := time.Now() for _, item := range f.Forecast { if item.Time.Format(time.DateOnly) != today.Format(time.DateOnly) { continue } itemTime := item.Time.Local() if helper.isUTC { itemTime = item.Time } t.Row( itemTime.Format("15:04"), fmt.Sprintf("%.1f °C", item.Temperature), fmt.Sprintf("%.1f mm", item.Percipitation), fmt.Sprintf("%.1f m/s %s", item.Wind.Speed, item.Wind.DirectionToString()), ) } fmt.Println(t) }