mirror of
https://github.com/pigmonkey/spark.git
synced 2026-01-23 02:24:09 +00:00
rework wttr wrapper
This commit is contained in:
parent
d90a74645e
commit
e65d68a455
1 changed files with 26 additions and 2 deletions
|
|
@ -1,3 +1,27 @@
|
|||
#!/bin/sh
|
||||
#!/bin/bash
|
||||
|
||||
curl wttr.in/"${1:-$(curl http://ip-api.com/json | jq 'if (.zip | length) != 0 then .zip else .city end')}"
|
||||
# Get the location from ip-api.com if the user didn't specify.
|
||||
location="$1"
|
||||
if [ -z "$1" ]; then
|
||||
location_data=$(curl -s http://ip-api.com/json)
|
||||
location=$(echo "$location_data" | jq -r 'if (.zip | length) != 0 then .zip else .city end')
|
||||
lat=$(echo "$location_data" | jq '.lat')
|
||||
lon=$(echo "$location_data" | jq '.lon')
|
||||
country=$(echo "$location_data" | jq -r '.country')
|
||||
fi
|
||||
|
||||
# Request the narrow version when appropriate.
|
||||
columns=$(tput cols)
|
||||
opts='?'
|
||||
if [ "$columns" -lt 125 ]; then
|
||||
opts+='n'
|
||||
fi
|
||||
|
||||
# If we fetched coordinates and are in the US, provide a URL to the detailed forecast.
|
||||
if [ "$country" == "United States" ] && [ -n "$lat" ] && [ -n "$lon" ]; then
|
||||
details="https://forecast.weather.gov/MapClick.php?lat=$lat&lon=$lon&FcstType=graphical&menu=1"
|
||||
fi
|
||||
|
||||
weather=$(curl -s -H "Accept-Language: ${LANG%_*}" --compressed wttr.in/"$location$opts")
|
||||
|
||||
echo "$weather"$'\n\n'"$details" | LESS="-F -w -R -X -z-4" less
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue