#!/usr/bin/perl
#
# WEATHER.PL v0.01
#
# try to grab Magdeburg info from weatherground.com
# and to display only needed content... at least it
# should do so.
###################################################
# by Frank Reppin (2002)
# shauwn@boerde.de
###################################################
# too small to license... pick GPL or sth similiar.
#
# Ah ... and thanks to the ppl at wunderground.com
# for providing worldwide weather data.
#
# You only need to edit $this_host ....
# and you have to grab the correct URL to your city
# from www.wunderground.com
# Magdeburg is 10361.html in this working example.
# This script behaves fine now since some weeks,
# I only had to remove the dataoutput for windchill
# since the dataoutput frequently changed at this
# positon and i've found no way how to better filter
# the html-file to get the correct values there.
# I'll leave the commented 'print's below if you
# want to check what's the output there.
#
# You can see this script in action at:
# http://amazone.boerde.de/mrtg/
#
###################################################

$this_host = "amazone.boerde.de";

system("wget -q http://www.wunderground.com/global/stations/10361.html -O /usr/local/mrtg-2/bin/addons/weather_temp.txt");
@Zeilen = ("");
open(WETTER, "</usr/local/mrtg-2/bin/addons/weather_temp.txt") || die "Uh... file not found.\n";
while(<WETTER>) {
	chomp;
	if (/<td>Temperature/ .. /<td>Dewpoint/) {
		s/<[^>]*>/ /gs;
		s/&#176\;/ /gs;
		s/%/ /gs;
		push(@Zeilen,$_);
					}
		}

$daten = join('', @Zeilen);

@output = split(/\s+/, $daten);
#$laenge_output = @output;
#print "$laenge_output\n";
#print "@output\n";
#print "$output[0]\n";
#print "$output[1]\n";
print "$output[2]\n";
#print "$output[3]\n";
#print "$output[4]\n";
#print "$output[5]\n";
#print "$output[6]\n";
#print "$output[7]\n";
#print "$output[8]\n";
#print "$output[9]\n";
#print "$output[10]\n";
#print "$output[11]\n";
#print "$output[12]\n";
#print "$output[13]\n";
#print "$output[14]\n";
close(WETTER);

print "0\n";
$uptime = `uptime`;

$uptime =~ /up (.*?),/;
$up = $1;
print "$up\n";
print "$this_host\n";
