-
Notifications
You must be signed in to change notification settings - Fork 9
Switch embedded weather skill to keyless wttr.in endpoint #354
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,13 +12,13 @@ metadata: | |
| requires: | ||
| bins: | ||
| - curl | ||
| - jq | ||
| env: | ||
| required: [] | ||
| one_of: [] | ||
| optional: [] | ||
| egress_domains: | ||
| - api.openweathermap.org | ||
| - api.weatherapi.com | ||
| - wttr.in | ||
| --- | ||
| ## Tool: weather_current | ||
|
|
||
|
|
@@ -27,9 +27,19 @@ Get current weather for a location. | |
| **Input:** location (string) - City name or coordinates | ||
| **Output:** Current temperature, conditions, humidity, and wind speed | ||
|
|
||
| ```bash | ||
| curl -s "https://wttr.in/${location}?format=j1" | ||
| ``` | ||
| Relevant fields in the response: `current_condition[0].temp_C`, `current_condition[0].weatherDesc[0].value`, `current_condition[0].humidity`, `current_condition[0].windspeedKmph`. | ||
|
|
||
| ## Tool: weather_forecast | ||
|
|
||
| Get weather forecast for a location. | ||
|
|
||
| **Input:** location (string), days (integer: 1-7) | ||
| **Input:** location (string), days (integer: 1-3) | ||
| **Output:** Daily forecast with high/low temperatures and conditions | ||
|
|
||
| ```bash | ||
| curl -s "https://wttr.in/${location}?format=j1" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here — this needs a |
||
| ``` | ||
| The `weather` array in the response contains up to 3 days of forecast (today + 2 days ahead). Each entry has `date`, `maxtempC`, `mintempC`, and `hourly[].weatherDesc[0].value`. wttr.in's free JSON endpoint caps at 3 days — for a longer forecast window, `open-meteo.com` would be needed instead. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| #!/usr/bin/env bash | ||
| set -euo pipefail | ||
|
|
||
| input="$1" | ||
|
|
||
| location=$(jq -r '.location // empty' <<< "$input" 2>/dev/null) || location="" | ||
|
|
||
| if [[ -z "$location" ]]; then | ||
| jq -n '{error: "location is required"}' | ||
| exit 0 | ||
| fi | ||
|
|
||
| encoded_location=$(jq -rn --arg s "$location" '$s|@uri') | ||
|
|
||
| response=$(curl -s -w "\n%{http_code}" "https://wttr.in/${encoded_location}?format=j1") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Optional (Low): under response=$(curl -s -w "\n%{http_code}" "https://wttr.in/${encoded_location}?format=j1") \
|| { jq -n '{error: "network request failed"}'; exit 0; }Same line in |
||
| http_code=$(tail -n1 <<< "$response") | ||
| body=$(sed '$d' <<< "$response") | ||
|
|
||
| if [[ "$http_code" != "200" ]]; then | ||
| jq -n --arg code "$http_code" '{error: "wttr.in request failed with status \($code)"}' | ||
| exit 0 | ||
| fi | ||
|
|
||
| echo "$body" | jq '{ | ||
| temperature_c: .current_condition[0].temp_C, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Optional (Low, cosmetic): wttr.in's j1 returns |
||
| condition: .current_condition[0].weatherDesc[0].value, | ||
| humidity: .current_condition[0].humidity, | ||
| wind_speed_kmph: .current_condition[0].windspeedKmph | ||
| }' 2>/dev/null || jq -n '{error: "failed to parse weather data"}' | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| #!/usr/bin/env bash | ||
| set -euo pipefail | ||
|
|
||
| input="$1" | ||
|
|
||
| location=$(jq -r '.location // empty' <<< "$input" 2>/dev/null) || location="" | ||
| days=$(jq -r '.days // 3' <<< "$input" 2>/dev/null) || days=3 | ||
|
|
||
| if [[ -z "$location" ]]; then | ||
| jq -n '{error: "location is required"}' | ||
| exit 0 | ||
| fi | ||
|
|
||
| if ! [[ "$days" =~ ^[0-9]+$ ]]; then | ||
| days=3 | ||
| fi | ||
| if (( days < 1 )); then days=1; fi | ||
| if (( days > 3 )); then days=3; fi | ||
|
|
||
| encoded_location=$(jq -rn --arg s "$location" '$s|@uri') | ||
|
|
||
| response=$(curl -s -w "\n%{http_code}" "https://wttr.in/${encoded_location}?format=j1") | ||
| http_code=$(tail -n1 <<< "$response") | ||
| body=$(sed '$d' <<< "$response") | ||
|
|
||
| if [[ "$http_code" != "200" ]]; then | ||
| jq -n --arg code "$http_code" '{error: "wttr.in request failed with status \($code)"}' | ||
| exit 0 | ||
| fi | ||
|
|
||
| echo "$body" | jq --argjson days "$days" '{ | ||
| forecast: [.weather[0:$days][] | { | ||
| date: .date, | ||
| max_temp_c: .maxtempC, | ||
| min_temp_c: .mintempC, | ||
| condition: .hourly[0].weatherDesc[0].value | ||
| }] | ||
| }' 2>/dev/null || jq -n '{error: "failed to parse forecast data"}' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This ```bash block is documentation — the runtime won't execute it. For
weather_currentto be a callable tool, add `scripts/weather-current.sh` (tool name with `_`→`-`) next to this SKILL.md. The script receives the tool's JSON input as its first argument, so it should parse `$1` with `jq`, pull `.location`, URL-encode it (`jq -rn --arg s "$LOCATION" '$s|@uri'`), curl wttr.in, check the HTTP status, and emit the shaped fields you list just below (`temp_C`, `weatherDesc`, `humidity`, `windspeedKmph`) rather than the full j1 blob. You'll also want `jq` added to `bins` above.