blob: 21706bc6e00629c8c31e312230e2390e60fffd9a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
#!/bin/bash
# Prints out the weather at your approximate location
get_weather()
{
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)
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" )
echo "";;
"Clouds" )
echo "摒";;
"Rain" )
echo "歹";;
"Thunderstorm" )
echo "朗";;
"Snow" )
echo "流";;
"Mist" )
echo "敖";;
* )
echo "?";;
esac
echo "$STATUS, "
echo "$TEMP°C"
}
get_weather
|