summaryrefslogtreecommitdiff
path: root/tint2_weather.sh
blob: eb600e10f2ddf49a6a62aa64b1a0db76219e7f73 (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

geo="$(wget -O- -q http://geoip.ubuntu.com/lookup)"
if grep -qi '88.96.115.94' <<< $geo; then
    lat="52.218011"
    lon="0.140549"
else
    lat="$(sed -r 's/.*<Latitude>(.*?)<\/Latitude>.*/\1/g' <<< $geo)"
    lon="$(sed -r 's/.*<Longitude>(.*?)<\/Longitude>.*/\1/g' <<< $geo)"
fi

weather="$(wget -q -O- http://api.wunderground.com/auto/wui/geo/WXCurrentObXML/index.xml?query=$lat,$lon)"

kw="weather"
condition="$(sed -r "s/.*<$kw>(.*?)<\/$kw>.*/\1/g" <<< $weather)"

kw="temp_c"
temperature="$(sed -r "s/.*<$kw>(.*?)<\/$kw>.*/\1/g" <<< $weather)"

kw="relative_humidity"
humidity="$(sed -r "s/.*<$kw>(.*?)<\/$kw>.*/\1/g" <<< $weather)"

kw="wind_mph"
wind="$(sed -r "s/.*<$kw>(.*?)<\/$kw>.*/\1/g" <<< $weather)"

kw="windchill_c"
feelslike="$(sed -r "s/.*<$kw>(.*?)<\/$kw>.*/\1/g" <<< $weather)"

if grep -qi 'rain' <<< $condition; then
    icon="⛆"
elif grep -qi 'storm' <<< $condition; then
    icon="⛈"
elif grep -qi 'cloud' <<< $condition; then
    icon="⛅"
elif grep -qi 'clear' <<< $condition; then
    icon="☼"
elif grep -qi 'snow' <<< $condition; then
    icon="⛄"
else
    icon=$condition
fi

firstline="${icon}  ${temperature}°C (${feelslike}°C) "
secondline="${wind:-0}km/h ${humidity}"

echo "${firstline:0:12}"
echo "${secondline:0:12}"