-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path58-weather
More file actions
26 lines (22 loc) · 815 Bytes
/
58-weather
File metadata and controls
26 lines (22 loc) · 815 Bytes
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
#!/bin/bash
# weather--Gets the weather for a specific region or ZIP code.
if [ $# -ne 1 ]; then
echo "Usage: $0 <zipcode>"
exit 1
fi
apikey="b0304b43b2e7cd23" # Not a real API key--you need your own.
weather=`curl -s \
"https://api.wunderground.com/api/$apikey/conditions/q/$1.xml"`
state=`xmllint --xpath \
//response/current_observation/display_location/full/text\(\) \
<(echo $weather)`
zip=`xmllint --xpath \
//response/current_observation/display_location/zip/text\(\) \
<(echo $weather)`
current=`xmllint --xpath \
//response/current_observation/temp_f/text\(\) \
<(echo $weather)`
condition=`xmllint --xpath \
//response/current_observation/weather/text\(\) \
<(echo $weather)`
echo $state" ("$zip") : Current temp "$current"F and "$condition" outside."