2024-09-29 17:20:59 +00:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
var nowCmd = &cobra.Command{
|
2024-09-29 18:31:42 +00:00
|
|
|
Use: "now <location>",
|
2024-09-29 17:20:59 +00:00
|
|
|
Aliases: []string{"current", "n"},
|
|
|
|
Short: "Get current forecasted weather",
|
2024-09-29 19:46:34 +00:00
|
|
|
Args: cobra.MaximumNArgs(1),
|
2024-09-29 18:31:42 +00:00
|
|
|
Run: now,
|
2024-09-29 17:20:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
rootCmd.AddCommand(nowCmd)
|
|
|
|
}
|
|
|
|
|
|
|
|
func now(cmd *cobra.Command, args []string) {
|
2024-10-04 18:39:05 +00:00
|
|
|
helper := forecastHelper(cmd, args)
|
|
|
|
f := helper.f
|
2024-09-29 17:20:59 +00:00
|
|
|
|
2024-10-04 18:39:05 +00:00
|
|
|
if helper.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 14:05:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
n := f.Forecast[0]
|
|
|
|
|
2024-10-04 18:39:05 +00:00
|
|
|
if helper.isJson {
|
2024-10-04 18:51:20 +00:00
|
|
|
outputJson(n)
|
2024-09-29 17:20:59 +00:00
|
|
|
}
|
|
|
|
|
2024-10-02 19:04:58 +00:00
|
|
|
itemTime := n.Time.Local()
|
2024-10-04 18:39:05 +00:00
|
|
|
if helper.isUTC {
|
2024-10-02 19:04:58 +00:00
|
|
|
itemTime = n.Time
|
|
|
|
}
|
2024-09-29 19:46:34 +00:00
|
|
|
fmt.Printf(
|
2024-10-03 20:48:50 +00:00
|
|
|
`%s %s:
|
2024-10-02 17:22:44 +00:00
|
|
|
Temperature: %.1f °C
|
|
|
|
Rain: %.1f mm
|
2024-10-02 19:04:58 +00:00
|
|
|
Wind: %.1f m/s from %s
|
|
|
|
`,
|
2024-09-29 19:46:34 +00:00
|
|
|
n.Location,
|
2024-10-03 20:48:50 +00:00
|
|
|
itemTime.Format("Monday 2 Jan 15:04"),
|
2024-09-29 19:46:34 +00:00
|
|
|
n.Temperature,
|
|
|
|
n.Percipitation,
|
2024-10-02 17:04:01 +00:00
|
|
|
n.Wind.Speed,
|
|
|
|
n.Wind.DirectionToString(),
|
2024-09-29 19:46:34 +00:00
|
|
|
)
|
2024-09-29 17:20:59 +00:00
|
|
|
}
|