summaryrefslogtreecommitdiff
path: root/tint2_weather.sh
diff options
context:
space:
mode:
Diffstat (limited to 'tint2_weather.sh')
-rwxr-xr-xtint2_weather.sh47
1 files changed, 47 insertions, 0 deletions
diff --git a/tint2_weather.sh b/tint2_weather.sh
new file mode 100755
index 0000000..eb600e1
--- /dev/null
+++ b/tint2_weather.sh
@@ -0,0 +1,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}"