2024-10-03 20:45:55 +00:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"git.sr.ht/~timharek/yr/cmd/internal/ui/table"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
var todayCmd = &cobra.Command{
|
2024-10-04 09:35:50 +00:00
|
|
|
Use: "today <location>",
|
|
|
|
Short: "Get tomorrow's forecasted weather",
|
|
|
|
Args: cobra.MaximumNArgs(1),
|
|
|
|
Run: today,
|
2024-10-03 20:45:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
rootCmd.AddCommand(todayCmd)
|
|
|
|
}
|
|
|
|
|
|
|
|
func today(cmd *cobra.Command, args []string) {
|
2024-10-17 14:36:54 +00:00
|
|
|
f := forecastHelper(args)
|
2024-10-03 20:45:55 +00:00
|
|
|
|
2024-10-17 14:36:54 +00:00
|
|
|
if isWeb {
|
2024-10-04 18:44:57 +00:00
|
|
|
openBrowser("https://www.yr.no/en/forecast/hourly-table/%.4f,%.4f?i=0", f)
|
2024-10-03 20:45:55 +00:00
|
|
|
}
|
|
|
|
|
2024-10-17 14:36:54 +00:00
|
|
|
if isJson {
|
2024-10-04 18:51:20 +00:00
|
|
|
outputJson(f.Forecast)
|
2024-10-03 20:45:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
t := table.New()
|
|
|
|
|
|
|
|
today := time.Now()
|
|
|
|
for _, item := range f.Forecast {
|
|
|
|
if item.Time.Format(time.DateOnly) != today.Format(time.DateOnly) {
|
|
|
|
continue
|
|
|
|
}
|
2024-10-17 14:36:54 +00:00
|
|
|
if !isUTC {
|
2024-10-04 21:38:23 +00:00
|
|
|
item.Time = item.Time.Local()
|
2024-10-03 20:45:55 +00:00
|
|
|
}
|
|
|
|
t.Row(
|
2024-10-04 21:38:23 +00:00
|
|
|
item.Time.Format("15:04"),
|
2024-10-03 20:45:55 +00:00
|
|
|
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)
|
|
|
|
}
|