From 4545d08ac81eab0cd9edce793f69b41f204aaf2f Mon Sep 17 00:00:00 2001 From: Momo Date: Sat, 6 Aug 2011 03:47:06 +0200 Subject: Added changes to Kachelmann so he can notify you when the weather changes --- kachelmann/changes | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 kachelmann/changes (limited to 'kachelmann/changes') diff --git a/kachelmann/changes b/kachelmann/changes new file mode 100644 index 00000000..dfd22b64 --- /dev/null +++ b/kachelmann/changes @@ -0,0 +1,31 @@ +#!/usr/bin/perl +use XML::Simple; +my $xml = new XML::Simple; +my $data_new = undef; +my $data_old = undef; + + +&startup; +while (true) { + if($status_new != $status_old){ + system("espeak -v de \"Das Wetter hat sich von $status_old in $status_new verändert\""); + } + sleep(300); + &get_status; +} + + +# The startup sub is used to get the first weather state. it should only be used on startup. sorry. +sub startup(){ + system("w3m -dump \"http://www.google.com/ig/api?weather=70327-stuttgart&hl=de\" > /tmp/kachelmann/weather.xml"); + $data_new = $xml->XMLin("/tmp/kachelmann/weather.xml"); + $data_new = $data_new->{weather}->{current_conditions}->{condition}->{data}; +} + +# The get_status sub moves the current data to $data_old and then gets a new one from Googles API +sub get_status(){ + system("w3m -dump \"http://www.google.com/ig/api?weather=70327-stuttgart&hl=de\" > /tmp/kachelmann/weather.xml"); + $data_old = $data_new; + $data_new = $xml->XMLin("/tmp/kachelmann/weather.xml"); + $data_new = $data_new->{weather}->{current_conditions}->{condition}->{data}; +} -- cgit v1.2.3 From 1fa3eb0e4e3acbe560e2091e47de3a245155baf2 Mon Sep 17 00:00:00 2001 From: Momo Date: Tue, 9 Aug 2011 08:10:37 +0200 Subject: Fixed changes and dumped the caching :) --- kachelmann/changes | 35 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 21 deletions(-) (limited to 'kachelmann/changes') diff --git a/kachelmann/changes b/kachelmann/changes index dfd22b64..1875dabd 100644 --- a/kachelmann/changes +++ b/kachelmann/changes @@ -1,31 +1,24 @@ #!/usr/bin/perl use XML::Simple; my $xml = new XML::Simple; +my $xml_store = undef; my $data_new = undef; my $data_old = undef; +my $condition_store = undef; -&startup; -while (true) { - if($status_new != $status_old){ - system("espeak -v de \"Das Wetter hat sich von $status_old in $status_new verändert\""); +my $data_old = $condition_store; +while (1) { + &xml_update(); + $data_new = $condition_store; + if($data_new == $data_old){ + system("espeak Das Wetter hat sich von $data_old in $data_new verändert"); } - sleep(300); - &get_status; + sleep 300; + $data_new = $data_old; } - - -# The startup sub is used to get the first weather state. it should only be used on startup. sorry. -sub startup(){ - system("w3m -dump \"http://www.google.com/ig/api?weather=70327-stuttgart&hl=de\" > /tmp/kachelmann/weather.xml"); - $data_new = $xml->XMLin("/tmp/kachelmann/weather.xml"); - $data_new = $data_new->{weather}->{current_conditions}->{condition}->{data}; -} - -# The get_status sub moves the current data to $data_old and then gets a new one from Googles API -sub get_status(){ - system("w3m -dump \"http://www.google.com/ig/api?weather=70327-stuttgart&hl=de\" > /tmp/kachelmann/weather.xml"); - $data_old = $data_new; - $data_new = $xml->XMLin("/tmp/kachelmann/weather.xml"); - $data_new = $data_new->{weather}->{current_conditions}->{condition}->{data}; +sub xml_update(){ + $xml_store = system("w3m -dump \"http://www.google.com/ig/api?weather=70327-stuttgart&hl=de\""); + $xml_store = $xml->XMLin($xml_store); + $condition_store = $xml_store->{weather}->{current_conditions}->{condition}->{data}; } -- cgit v1.2.3