Skip to content

Instantly share code, notes, and snippets.

@crshmk
Last active May 8, 2026 20:54
Show Gist options
  • Select an option

  • Save crshmk/fd7e838fff8d0f34e52de58c4e8edd6b to your computer and use it in GitHub Desktop.

Select an option

Save crshmk/fd7e838fff8d0f34e52de58c4e8edd6b to your computer and use it in GitHub Desktop.
terminal weather
#!/usr/bin/env bash
LAT="37.0833"
LON="-79.9"
URL=$(curl -s "https://api.weather.gov/points/$LAT,$LON" \
| jq -r '.properties.forecast')
DATA=$(curl -s "$URL")
printf "\n%-5s %-6s %-6s\n" "Day" "High" "Low"
printf "%-5s %-6s %-6s\n" "-----" "------" "------"
for DAY in Mon Tue Wed Thu Fri Sat Sun; do
HIGH=$(echo "$DATA" | jq -r \
--arg d "$DAY" '
.properties.periods[]
| select(.isDaytime == true)
| select(.name[0:3] == $d)
| .temperature
' | head -1)
LOW=$(echo "$DATA" | jq -r \
--arg d "$DAY" '
.properties.periods[]
| select(.isDaytime == false)
| select(.name[0:3] == $d or (.name == "Tonight" and $d == "Fri"))
| .temperature
' | head -1)
[[ "$HIGH" != "" && "$LOW" != "" ]] && \
printf "%-5s %-6s %-6s\n" "$DAY" "${HIGH}°" "${LOW}°"
done
#!/usr/bin/env bash
LAT="37.0833"
LON="-79.9"
URL=$(curl -s "https://api.weather.gov/points/$LAT,$LON" \
| jq -r '.properties.forecast')
DATA=$(curl -s "$URL")
printf "\n%-5s %-6s %-6s\n" "Day" "High" "Low"
printf "%-5s %-6s %-6s\n" "-----" "------" "------"
for DAY in Mon Tue Wed Thu Fri Sat Sun; do
HIGH=$(echo "$DATA" | jq -r \
--arg d "$DAY" '
.properties.periods[]
| select(.isDaytime == true)
| select(.name[0:3] == $d)
| .temperature
' | head -1)
LOW=$(echo "$DATA" | jq -r \
--arg d "$DAY" '
.properties.periods[]
| select(.isDaytime == false)
| select(.name[0:3] == $d or (.name == "Tonight" and $d == "Fri"))
| .temperature
' | head -1)
[[ "$HIGH" != "" && "$LOW" != "" ]] && \
printf "%-5s %-6s %-6s\n" "$DAY" "${HIGH}°" "${LOW}°"
done
#!/usr/bin/env bash
LAT="37.0833"
LON="-79.9"
URL=$(curl -s "https://api.weather.gov/points/$LAT,$LON" |
jq -r '.properties.forecast')
DATA=$(curl -s "$URL")
printf "\n%-16s %-6s %-6s %-8s %-12s\n" \
"Day" "High" "Low" "Rain" "Wind"
printf "%-16s %-6s %-6s %-8s %-12s\n" \
"---------------" "------" "------" "------" "------------"
echo "$DATA" | jq -r '
.properties.periods
| to_entries[]
| select(.value.isDaytime == true)
| [
.key,
.value.name,
(.value.temperature | tostring),
((.value.probabilityOfPrecipitation.value // 0) | tostring),
(.value.windSpeed | gsub(" to "; "-"))
]
| @tsv
' | while IFS=$'\t' read -r IDX DAY HIGH RAIN WIND; do
LOW=$(echo "$DATA" | jq -r --argjson i "$IDX" '
.properties.periods[$i + 1].temperature // empty
')
[[ -n "$LOW" ]] && LOW="${LOW}°" || LOW="-"
printf "%-16s %6s %6s %7s%% %12s\n" \
"$DAY" \
"${HIGH}°" \
"${LOW}" \
"$RAIN" \
"$WIND"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment