2019-10-21 18:32:48 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# Prints out the weather at your approximate location
|
2019-10-21 18:42:40 +00:00
|
|
|
# Needs an internet connection
|
|
|
|
# Dependencies: jq
|
|
|
|
|
|
|
|
SUN_ICON=''
|
|
|
|
CLOUD_ICON='摒'
|
|
|
|
RAIN_ICON='歹'
|
|
|
|
THUNDER_ICON='朗'
|
|
|
|
SNOW_ICON='流'
|
|
|
|
MIST_ICON='敖'
|
2019-10-21 18:32:48 +00:00
|
|
|
|
|
|
|
get_weather()
|
|
|
|
{
|
2019-10-21 18:34:53 +00:00
|
|
|
LOCATION=$(curl -s http://ip-api.com/json | \
|
|
|
|
jq '.lat, .lon' | \
|
|
|
|
while read -r LATITUDE; do
|
|
|
|
read -r LONGITUDE
|
|
|
|
echo "${LATITUDE}:${LONGITUDE}" | tr -d '"'
|
|
|
|
done)
|
|
|
|
|
2019-10-21 18:32:48 +00:00
|
|
|
LANG="en"
|
|
|
|
UNITS="Metric"
|
|
|
|
API_KEY="756edce7e9d4c385ef9499a53492678c"
|
|
|
|
|
|
|
|
LOCATION_FORMATTED_2=$(echo $LOCATION | cut -d ':' -f2)
|
|
|
|
LOCATION_FORMATTED_1=$(echo $LOCATION | cut -d ':' -f1)
|
|
|
|
|
|
|
|
OUTPUT=$(curl -s "http://api.openweathermap.org/data/2.5/weather?lat=$LOCATION_FORMATTED_1&lon=$LOCATION_FORMATTED_2&lang=$LANG&appid=$API_KEY&units=$UNITS")
|
|
|
|
STATUS=$(echo $OUTPUT | jq '.weather' | tr '[' ' ' | tr ']' ' ' | jq '.main' | sed 's/"//g')
|
|
|
|
TEMP=$(echo $OUTPUT | jq '.main' | jq '.temp' | xargs printf "%.*f\n" 0)
|
|
|
|
|
|
|
|
case $STATUS in
|
|
|
|
"Clear" )
|
2019-10-21 18:42:40 +00:00
|
|
|
echo $SUN_ICON;;
|
2019-10-21 18:32:48 +00:00
|
|
|
"Clouds" )
|
2019-10-21 18:42:40 +00:00
|
|
|
echo $CLOUD_ICON;;
|
2019-10-21 18:32:48 +00:00
|
|
|
"Rain" )
|
2019-10-21 18:42:40 +00:00
|
|
|
echo $RAIN_ICON;;
|
2019-10-21 18:32:48 +00:00
|
|
|
"Thunderstorm" )
|
2019-10-21 18:42:40 +00:00
|
|
|
echo $THUNDER_ICON;;
|
2019-10-21 18:32:48 +00:00
|
|
|
"Snow" )
|
2019-10-21 18:42:40 +00:00
|
|
|
echo $SNOW_ICON;;
|
2019-10-21 18:32:48 +00:00
|
|
|
"Mist" )
|
2019-10-21 18:42:40 +00:00
|
|
|
echo $MIST_ICON;;
|
2019-10-21 18:32:48 +00:00
|
|
|
* )
|
2019-10-21 18:42:40 +00:00
|
|
|
echo "?";;
|
|
|
|
esac
|
2019-10-21 18:32:48 +00:00
|
|
|
|
2019-10-21 18:42:40 +00:00
|
|
|
echo "$STATUS, "
|
|
|
|
echo "$TEMP°C"
|
2019-10-21 18:32:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get_weather
|
|
|
|
|