Skip to content

Commit 42ba60b

Browse files
authored
chore: weather tool (#472)
Signed-off-by: Taylor Price <[email protected]>
1 parent 5f42649 commit 42ba60b

File tree

4 files changed

+74
-0
lines changed

4 files changed

+74
-0
lines changed

weather/go.mod

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module github.com/obot-platform/tools/weather
2+
3+
go 1.24.0
4+
5+
require github.com/icodealot/noaa v0.0.2

weather/go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
github.com/icodealot/noaa v0.0.2 h1:nL21mFSxJUBog7/0/vakIfA109T2A8/JpowzEzL9O+w=
2+
github.com/icodealot/noaa v0.0.2/go.mod h1:vPMSrP4zBvlbWC34qtUR5w64dCp0xSRjkLy9/Ky81go=

weather/main.go

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"github.com/icodealot/noaa"
6+
"log"
7+
"os"
8+
)
9+
10+
func main() {
11+
if len(os.Args) < 2 {
12+
log.Fatal("usage: weather <command>")
13+
}
14+
15+
command := os.Args[1]
16+
17+
latitude := os.Getenv("LATITUDE")
18+
if latitude == "" {
19+
log.Fatal("required latitude parameter not set")
20+
}
21+
longitude := os.Getenv("LONGITUDE")
22+
if longitude == "" {
23+
log.Fatal("required longitude parameter not set")
24+
}
25+
26+
switch command {
27+
case "getWeeklyForecast":
28+
forecast, err := noaa.Forecast(latitude, longitude)
29+
if err != nil {
30+
log.Fatalf("error getting the forecast: %v", err)
31+
return
32+
}
33+
for _, period := range forecast.Periods {
34+
fmt.Printf("%-20s ---> %.0f%s\n", period.Name, period.Temperature, period.TemperatureUnit)
35+
}
36+
case "getHourlyForecast":
37+
forecast, err := noaa.HourlyForecast(latitude, longitude)
38+
if err != nil {
39+
log.Fatalf("error getting the forecast: %v", err)
40+
}
41+
for _, period := range forecast.Periods {
42+
fmt.Printf("%-20s ---> %.0f%s\n", period.StartTime, period.Temperature, period.TemperatureUnit)
43+
}
44+
}
45+
46+
}

weather/tool.gpt

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
Name: Weather
3+
Description: Tools for getting the weather forecast
4+
Metadata: bundle: true
5+
Share Tools: Get Weekly Forecast, Get Hourly Forecast
6+
7+
---
8+
Name: Get Weekly Forecast
9+
Description: Gets the weekly forecast for a given latitude and longitude
10+
Param: latitude: The latitude to look up the forecast for
11+
Param: longitude: The longitude to look up the forecast for
12+
13+
#!${GPTSCRIPT_TOOL_DIR}/bin/gptscript-go-tool getWeeklyForecast
14+
15+
---
16+
Name: Get Hourly Forecast
17+
Description: Gets the hourly forecast for a given latitude and longitude
18+
Param: latitude: The latitude to look up the forecast for
19+
Param: longitude: The longitude to look up the forecast for
20+
21+
#!${GPTSCRIPT_TOOL_DIR}/bin/gptscript-go-tool getHourlyForecast

0 commit comments

Comments
 (0)