Skip to content

Instantly share code, notes, and snippets.

@sentriz
Last active July 19, 2023 22:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sentriz/5ac57ef9cf21f360650c7748d9d9bfa2 to your computer and use it in GitHub Desktop.
Save sentriz/5ac57ef9cf21f360650c7748d9d9bfa2 to your computer and use it in GitHub Desktop.
precipitation from api.met.no with graph in shell
#!/usr/bin/env fish
set lat "53.350140"
set lon "-6.266155"
set url "https://api.met.no/weatherapi/locationforecast/2.0/classic?lat=$lat;lon=$lon"
set point_per_mm 10
function parse
jq -r \
--argjson start (date -d (date -u +"%Y-%m-%dT%H:00:00Z") +%s) \
--argjson inc 3600 \
'
.weatherdata.product.time
| .[]
| select((."@from" | fromdate) >= $start and (."@to" | fromdate) == ((."@from" | fromdate) + $inc))
| select(.location.precipitation?)
| "\(."@from")\t\(.location.precipitation."@value")"
'
end
function format
while read -d \t date mm
printf "%s\t%s\t%smm\t%s░\n" \
(date -d $date "+%A" | lower) \
(date -d $date "+%H:%M") \
$mm \
(string repeat -n (printf "%.0f" (math "$mm * $point_per_mm")) ▒)
end
end
function table
column -t -s \t --table-noheadings -C name=day -C name=time,right -C name=mm,right -C name=bar,trunc
end
curl -s "$url" | rsl xml json | parse | format | table
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment