From d1c94191761906a4741635cb585e5df09118d625 Mon Sep 17 00:00:00 2001 From: Taylor Price Date: Fri, 21 Feb 2025 19:23:30 -0700 Subject: [PATCH] chore: weather tool Signed-off-by: Taylor Price --- weather/go.mod | 5 +++++ weather/go.sum | 2 ++ weather/main.go | 46 ++++++++++++++++++++++++++++++++++++++++++++++ weather/tool.gpt | 21 +++++++++++++++++++++ 4 files changed, 74 insertions(+) create mode 100644 weather/go.mod create mode 100644 weather/go.sum create mode 100644 weather/main.go create mode 100644 weather/tool.gpt diff --git a/weather/go.mod b/weather/go.mod new file mode 100644 index 00000000..ab4f3743 --- /dev/null +++ b/weather/go.mod @@ -0,0 +1,5 @@ +module github.com/obot-platform/tools/weather + +go 1.24.0 + +require github.com/icodealot/noaa v0.0.2 diff --git a/weather/go.sum b/weather/go.sum new file mode 100644 index 00000000..b066e83a --- /dev/null +++ b/weather/go.sum @@ -0,0 +1,2 @@ +github.com/icodealot/noaa v0.0.2 h1:nL21mFSxJUBog7/0/vakIfA109T2A8/JpowzEzL9O+w= +github.com/icodealot/noaa v0.0.2/go.mod h1:vPMSrP4zBvlbWC34qtUR5w64dCp0xSRjkLy9/Ky81go= diff --git a/weather/main.go b/weather/main.go new file mode 100644 index 00000000..f9285558 --- /dev/null +++ b/weather/main.go @@ -0,0 +1,46 @@ +package main + +import ( + "fmt" + "github.com/icodealot/noaa" + "log" + "os" +) + +func main() { + if len(os.Args) < 2 { + log.Fatal("usage: weather ") + } + + command := os.Args[1] + + latitude := os.Getenv("LATITUDE") + if latitude == "" { + log.Fatal("required latitude parameter not set") + } + longitude := os.Getenv("LONGITUDE") + if longitude == "" { + log.Fatal("required longitude parameter not set") + } + + switch command { + case "getWeeklyForecast": + forecast, err := noaa.Forecast(latitude, longitude) + if err != nil { + log.Fatalf("error getting the forecast: %v", err) + return + } + for _, period := range forecast.Periods { + fmt.Printf("%-20s ---> %.0f%s\n", period.Name, period.Temperature, period.TemperatureUnit) + } + case "getHourlyForecast": + forecast, err := noaa.HourlyForecast(latitude, longitude) + if err != nil { + log.Fatalf("error getting the forecast: %v", err) + } + for _, period := range forecast.Periods { + fmt.Printf("%-20s ---> %.0f%s\n", period.StartTime, period.Temperature, period.TemperatureUnit) + } + } + +} diff --git a/weather/tool.gpt b/weather/tool.gpt new file mode 100644 index 00000000..02e2e88f --- /dev/null +++ b/weather/tool.gpt @@ -0,0 +1,21 @@ +--- +Name: Weather +Description: Tools for getting the weather forecast +Metadata: bundle: true +Share Tools: Get Weekly Forecast, Get Hourly Forecast + +--- +Name: Get Weekly Forecast +Description: Gets the weekly forecast for a given latitude and longitude +Param: latitude: The latitude to look up the forecast for +Param: longitude: The longitude to look up the forecast for + +#!${GPTSCRIPT_TOOL_DIR}/bin/gptscript-go-tool getWeeklyForecast + +--- +Name: Get Hourly Forecast +Description: Gets the hourly forecast for a given latitude and longitude +Param: latitude: The latitude to look up the forecast for +Param: longitude: The longitude to look up the forecast for + +#!${GPTSCRIPT_TOOL_DIR}/bin/gptscript-go-tool getHourlyForecast \ No newline at end of file