/
weather.sh
48 lines (41 loc) · 1.06 KB
/
weather.sh
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
48
#!/bin/bash
#####################################
## Get Weather from Yahoo
## Name: Tobias Schug
## Email: Tobiasschug@gmail.com
## Coded: 25.05.2009
## Version 0.1
## Funktion gegeben
## Version 0.2
## Unnötige Operationen verhindert
## Version 0.3
## Url Fix
## Version 0.3.1
## remote sed pipe
## Version 0.3.2
## clean code
##
## Information:
## at: http://weather.yahoo.com you can get your weather url
##
#####################################
#path where u save the picture
user="$HOME/Documents/GeektoolScripts/weather.jpg"
#Yahoo url
url="http://ca.weather.yahoo.com/forecast/GMXX1144.html"
picture=$(curl --silent $url | grep '<div id="weather_icon"' | sed -e "s?.*url(??; s?).*??")
# download only if internet connection is available
if [ "$picture" != "" ]
then
#download the picture
curl --silent $picture -o $user
fi
#get temp
temp=$(curl --silent $url | grep -A 1 'Feels Like:' | sed -e 's/.*<dd>//;s/&.*//;s?.*</dt>??')
# write 100 C if internet connection is not available
if [ "$temp" == "" ]
then
echo "100 C"
else
echo Temperatur: $temp C
fi