🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

16 total messages Started by Mark Anderson Mon, 26 Nov 2012 00:21
Parse wunderground.com
#119
Author: Mark Anderson
Date: Mon, 26 Nov 2012 00:21
140 lines
5535 bytes
While listening to the Bears game I wrote this little perl script to 
parse the output of wget to wunderground.com and get the current temp, 
wind speed, and a bunch of other stuff and put it into a comma 
deliminated file.  I figured I'd post it here in case anyone needs to 
extract weather info from that site.  If they change up the web site 
this script will probably need a tweak.  Hopefully this saves someone 
some time.  I checked out the wunderground perl CPAN module but I wanted 
to target the station in my neighborhood which couldn't be done with 
that module.  The temp here can be many degrees different than the temp 
at Ohare.

Wget writes a file ddd.dat with the wunderground raw html data which the 
perl script reads.  There may be  more elegant ways of doing this.  The 
bash shell script calls wget, the perl script, and timestamps the comma 
deliminated data.  I have it currently set to loop every 15 minutes but 
will probably extend that to an hour.  The perl script is the meat and 
potatoes since I had to decipher their html structure and attributes 
they use to id the various data.

I use a simple bash shell script in an infinite loop to call it.
(change /home/mea to your path)

#!/bin/bash

# Script to log temperature data from
# wunderground.com


for (( ; ; ))
do
	wget "paste_your_location_specific_wunderground_url_here"  -O 
/home/mea/ddd.dat  -a /home/mea/log.dat


/home/mea/parse_weather.sh
echo "," `date +%H%M%m%d`

sleep 900
done


And then the perl script.

#!/usr/bin/perl
use strict  ;
use warnings  ;

# Parse weather underground for current
# temperature.  The site will captured
# using wget and placed into a file
# called ddd.dat.
#
# This script just parses that html
# and extracts the current temperature,
# then timestamps and appends it to
# weather.dat.  It is the responsibility
# of the calling script to manage that
# data (i.e. rotate it into a more permanent
# location).

use IO::File ;
use HTML::TreeBuilder ;

my @elements2 = {};
my @stripchars = ( q[\xa0]  , q[\xb0] ,  "Feels Like " , "F")  ;

	my $document = ""  ;  #the input document
	$document =  new IO::File;
	$document ->  open( "/home/mea/ddd.dat" );

	my $tree = HTML::TreeBuilder->new; # empty tree
	$tree->parse_file($document);

#---------LOOK DOWN HTML--------POPULATE @elements2-------------

	
	@elements2 = $tree -> look_down( 
				sub {
				      $_[0] -> tag eq 'div'  or
				      $_[0] -> tag eq 'span' 
				}
			)  ;
#	print "num of div elements=$#elements2\n"   ;
	my $idx = ""  ;
	my $temp = ""  ;
	my $windspeed = ""  ;
	my $windcompass = ""  ;
	my $sunrise  = ""  ;
	my $sunset   = ""  ;
	my $cond = ""  ;
	my $humidity = ""  ;
	my $pressure = ""  ;
	my $tempfeel = ""  ;
	
	foreach my $para (@elements2)   {

		if ($idx = $para -> attr("id")) {  

			if ($idx eq "tempActual")  {
				$temp = $para -> as_trimmed_text  ;
				foreach my $strip (@stripchars) {
					$temp =~ s/$strip//g  ;
				}
			}
			if ($idx eq "tempFeel")  {
				$tempfeel = $para -> as_trimmed_text  ;
				foreach my $strip (@stripchars) {
					$tempfeel =~ s/$strip//g  ;
				}
			}
			if ($idx eq "windCompassContainer" )  {
				$windspeed = $para -> as_trimmed_text  ;
			}
			if ($idx eq "sRise")  {
				$sunrise = $para -> as_trimmed_text  ;
			}
			if ($idx eq "sSet")  {
				$sunset  = $para -> as_trimmed_text  ;
			}
			if ($idx eq "curCond")  {
				$cond = $para -> as_trimmed_text  ;
			}
			if ($idx eq "windCompass" )  {
				if($windcompass = $para -> attr("value")) {}
				else { $windcompass="error" ; }
			}
		}
		if ($idx = $para -> attr("pwsvariable")) {  
			if ($idx eq "baromin")  {
				if($pressure = $para -> attr("value")) {}
				else { $pressure="error" ; }
			}
			if ($idx eq "humidity")  {
				$humidity = $para -> as_trimmed_text  ;
			}
		}

	}
	print "$temp,$tempfeel,$windspeed,$windcompass,$sunrise,$sunset,
$cond,$humidity,$pressure"  ;
Re: Parse wunderground.com
#120
Author: Cydrome Leader
Date: Mon, 26 Nov 2012 00:56
152 lines
7251 bytes
Mark Anderson <mea@nospambradnylion.com> wrote:
> While listening to the Bears game I wrote this little perl script to 
> parse the output of wget to wunderground.com and get the current temp, 
> wind speed, and a bunch of other stuff and put it into a comma 
> deliminated file.  I figured I'd post it here in case anyone needs to 
> extract weather info from that site.  If they change up the web site 
> this script will probably need a tweak.  Hopefully this saves someone 
> some time.  I checked out the wunderground perl CPAN module but I wanted 
> to target the station in my neighborhood which couldn't be done with 
> that module.  The temp here can be many degrees different than the temp 
> at Ohare.
> 
> Wget writes a file ddd.dat with the wunderground raw html data which the 
> perl script reads.  There may be  more elegant ways of doing this.  The 
> bash shell script calls wget, the perl script, and timestamps the comma 
> deliminated data.  I have it currently set to loop every 15 minutes but 
> will probably extend that to an hour.  The perl script is the meat and 
> potatoes since I had to decipher their html structure and attributes 
> they use to id the various data.
> 
> I use a simple bash shell script in an infinite loop to call it.
> (change /home/mea to your path)
> 
> #!/bin/bash
> 
> # Script to log temperature data from
> # wunderground.com
> 
> 
> for (( ; ; ))
> do
>        wget "paste_your_location_specific_wunderground_url_here"  -O 
> /home/mea/ddd.dat  -a /home/mea/log.dat
> 
> 
> /home/mea/parse_weather.sh
> echo "," `date +%H%M%m%d`
> 
> sleep 900
> done
> 
> 
> And then the perl script.
> 
> #!/usr/bin/perl
> use strict  ;
> use warnings  ;
> 
> # Parse weather underground for current
> # temperature.  The site will captured
> # using wget and placed into a file
> # called ddd.dat.
> #
> # This script just parses that html
> # and extracts the current temperature,
> # then timestamps and appends it to
> # weather.dat.  It is the responsibility
> # of the calling script to manage that
> # data (i.e. rotate it into a more permanent
> # location).
> 
> use IO::File ;
> use HTML::TreeBuilder ;
> 
> my @elements2 = {};
> my @stripchars = ( q[\xa0]  , q[\xb0] ,  "Feels Like " , "F")  ;
> 
>        my $document = ""  ;  #the input document
>        $document =  new IO::File;
>        $document ->  open( "/home/mea/ddd.dat" );
> 
>        my $tree = HTML::TreeBuilder->new; # empty tree
>        $tree->parse_file($document);
> 
> #---------LOOK DOWN HTML--------POPULATE @elements2-------------
> 
>        
>        @elements2 = $tree -> look_down( 
>                                sub {
>                                      $_[0] -> tag eq 'div'  or
>                                      $_[0] -> tag eq 'span' 
>                                }
>                        )  ;
> #       print "num of div elements=$#elements2\n"   ;
>        my $idx = ""  ;
>        my $temp = ""  ;
>        my $windspeed = ""  ;
>        my $windcompass = ""  ;
>        my $sunrise  = ""  ;
>        my $sunset   = ""  ;
>        my $cond = ""  ;
>        my $humidity = ""  ;
>        my $pressure = ""  ;
>        my $tempfeel = ""  ;
>        
>        foreach my $para (@elements2)   {
> 
>                if ($idx = $para -> attr("id")) {  
> 
>                        if ($idx eq "tempActual")  {
>                                $temp = $para -> as_trimmed_text  ;
>                                foreach my $strip (@stripchars) {
>                                        $temp =~ s/$strip//g  ;
>                                }
>                        }
>                        if ($idx eq "tempFeel")  {
>                                $tempfeel = $para -> as_trimmed_text  ;
>                                foreach my $strip (@stripchars) {
>                                        $tempfeel =~ s/$strip//g  ;
>                                }
>                        }
>                        if ($idx eq "windCompassContainer" )  {
>                                $windspeed = $para -> as_trimmed_text  ;
>                        }
>                        if ($idx eq "sRise")  {
>                                $sunrise = $para -> as_trimmed_text  ;
>                        }
>                        if ($idx eq "sSet")  {
>                                $sunset  = $para -> as_trimmed_text  ;
>                        }
>                        if ($idx eq "curCond")  {
>                                $cond = $para -> as_trimmed_text  ;
>                        }
>                        if ($idx eq "windCompass" )  {
>                                if($windcompass = $para -> attr("value")) {}
>                                else { $windcompass="error" ; }
>                        }
>                }
>                if ($idx = $para -> attr("pwsvariable")) {  
>                        if ($idx eq "baromin")  {
>                                if($pressure = $para -> attr("value")) {}
>                                else { $pressure="error" ; }
>                        }
>                        if ($idx eq "humidity")  {
>                                $humidity = $para -> as_trimmed_text  ;
>                        }
>                }
> 
>        }
>        print "$temp,$tempfeel,$windspeed,$windcompass,$sunrise,$sunset,
> $cond,$humidity,$pressure"  ;
> 
> 

wow. 

Why not just add 10 characters of awk to my version of whatever the hell
you're trying to do up there.

Anybody that uses perl isn't a programmer.

 wget -qO- "http://rss.wunderground.com/auto/rss_full/IL/Chicago.xml?units=english" | grep Temp
Re: Parse wunderground.com
#121
Author: Mark Anderson
Date: Mon, 26 Nov 2012 03:18
33 lines
3261 bytes
In article presence@MUNGEpanix.com says...
> wow. 
> 
> Why not just add 10 characters of awk to my version of whatever the hell
> you're trying to do up there.
> 
> Anybody that uses perl isn't a programmer.
> 
>  wget -qO- "http://rss.wunderground.com/auto/rss_full/IL/Chicago.xml?units=english" | grep Temp

That's interesting.  I couldn't find an xml or rss version like this for 
my neighborhood.  I hit a specific weather station that's linked to my 
zip code which is some cgi script on their side.  For what I'm using 
this data for I do need as close as local as possible so even Ohare or 
Midway data would be off -- sometimes by a lot.  Remember the so called 
20 inches of snow?

Normally I prefer to awk but html with all its backslashes and >< and 
general fuckery makes choosing a field separator rather challenging.  
Then you have to clean with substr which can be a PITA.  The 
HTML::TreeBuilder breaks up html code into teeny little objects that can 
be sliced and diced in a civilized manner.

I started out to just extract current temp, timestamp it, and log it.  
Then a what the heck moment came because the Bears were kicking ass and 
it became trivial to get a bunch of other data too.  Wunderground hid 
key attributes in both div and span statements so the script had to 
slice up html on both tags.  They also do funny characters like &nbsp 
and &deg which has to be stripped in order not to corrupt a text file 
with non ASCII crap.

The resulting data which is CSV will probably get piped through awk one 
day.
Re: Parse wunderground.com
#122
Author: Robert Bonomi
Date: Tue, 27 Nov 2012 19:43
24 lines
2552 bytes
In article <MPG.2b1ca9a129fca2e7989a66@news.speakeasy.net>,
Mark Anderson  <mea@nospambradnylion.com> wrote:
>In article presence@MUNGEpanix.com says...
>> wow. 
>> 
>> Why not just add 10 characters of awk to my version of whatever the hell
>> you're trying to do up there.
>> 
>> Anybody that uses perl isn't a programmer.
>> 
>>  wget -qO-
>"http://rss.wunderground.com/auto/rss_full/IL/Chicago.xml?units=english"
>| grep Temp
>
>That's interesting.  I couldn't find an xml or rss version like this for 
>my neighborhood.  I hit a specific weather station that's linked to my 
>zip code which is some cgi script on their side.  

Why not do this the *EASY* way??

  $ station=KIlCHI69   # or whatever the 'neighborhood' station is you want
  $ page='weatherstation/WXDailyHistory.asp'
  $ parms='ID='${station}'&wuSelect=PWS&format=1'
  $ wget -qO- http://www.wunderground.com/${page}?${parms} >${station}.csv
Re: Parse wunderground.com
#123
Author: Mark Anderson
Date: Tue, 27 Nov 2012 20:46
13 lines
2298 bytes
In article bonomi@host122.r-bonomi.com says...
> Why not do this the *EASY* way??
> 
>   $ station=KIlCHI69   # or whatever the 'neighborhood' station is you want
>   $ page='weatherstation/WXDailyHistory.asp'
>   $ parms='ID='${station}'&wuSelect=PWS&format=1'
>   $ wget -qO- http://www.wunderground.com/${page}?${parms} >${station}.csv

Ughh.  I can't believe I missed this!  According to my browser history I 
was at the local PWS site once.  Thanks.  Your script is simpler and awk 
friendly.  :-)  That site keeps track of historical data too so I really 
don't even need to do this.  Maybe I'll tail -n1 your script, pipe it 
into awk and put a little weather doohickey on the desktop.
Re: Parse wunderground.com
#124
Author: Cydrome Leader
Date: Wed, 28 Nov 2012 17:53
17 lines
2261 bytes
Mark Anderson <mea@nospambradnylion.com> wrote:
> In article bonomi@host122.r-bonomi.com says...
>> Why not do this the *EASY* way??
>> 
>>   $ station=KIlCHI69   # or whatever the 'neighborhood' station is you want
>>   $ page='weatherstation/WXDailyHistory.asp'
>>   $ parms='ID='${station}'&wuSelect=PWS&format=1'
>>   $ wget -qO- http://www.wunderground.com/${page}?${parms} >${station}.csv
> 
> Ughh.  I can't believe I missed this!  According to my browser history I 
> was at the local PWS site once.  Thanks.  Your script is simpler and awk 
> friendly.  :-)  That site keeps track of historical data too so I really 
> don't even need to do this.  Maybe I'll tail -n1 your script, pipe it 
> into awk and put a little weather doohickey on the desktop.

If you run that trash called linux just use the watch command to loop the 
wget over and over again.
Re: Parse wunderground.com
#126
Author: Mark Anderson
Date: Sun, 02 Dec 2012 19:02
21 lines
3040 bytes
In article presence@MUNGEpanix.com says...
> If you run that trash called linux just use the watch command to loop the 
> wget over and over again.

Yeah, the old watch command.  I just recently discovered it and I 
suppose it can provide a simple no nonsense solution for displays that 
have a lot of windows with a lot data updating.

Do you happen to know of a little applet that will emulate a one line 
terminal that can be put onto a panel on the desktop (i.e. no standard 
window borders)?  I looked and looked and looked and can't find 
anything.  This seems like a useful applet to display practically 
anything using that watch command.  I would have thought someone would 
have written one by now.  It could even just display text output from 
another process.  Based on what happened last Sunday during the Bears 
game, before I dive into writing a Java applet I'll wait.  This seems 
like a beginner program.  Although I rely on Google every day, it 
doesn't do well when searching for stuff like this or I can't figure out 
the right search terms.

I can easily do it with perl/tk but I want it on the panel.
Re: Parse wunderground.com
#127
Author: Cydrome Leader
Date: Mon, 03 Dec 2012 03:53
16 lines
2002 bytes
Mark Anderson <mea@nospambradnylion.com> wrote:
> In article presence@MUNGEpanix.com says...
>> If you run that trash called linux just use the watch command to loop the 
>> wget over and over again.
> 
> Yeah, the old watch command.  I just recently discovered it and I 
> suppose it can provide a simple no nonsense solution for displays that 
> have a lot of windows with a lot data updating.
> 
> Do you happen to know of a little applet that will emulate a one line 
> terminal that can be put onto a panel on the desktop (i.e. no standard 
> window borders)?  I looked and looked and looked and can't find 

nope.

If you run windows, this is probably a 5 line VB program.
Re: Parse wunderground.com
#128
Author: Mark Anderson
Date: Mon, 03 Dec 2012 05:44
14 lines
2404 bytes
In article presence@MUNGEpanix.com says...
> > Do you happen to know of a little applet that will emulate a one 
line 
> > terminal that can be put onto a panel on the desktop (i.e. no standard 
> > window borders)?  I looked and looked and looked and can't find 
> 
> nope.
> 
> If you run windows, this is probably a 5 line VB program.

Does that include a GOTO 10 or  CLR statement?

BTW: Maybe the Bears would have won if I had tried to write the Java 
applet.  :-)
Re: Parse wunderground.com
#129
Author: Cydrome Leader
Date: Thu, 06 Dec 2012 18:09
16 lines
1960 bytes
Mark Anderson <mea@nospambradnylion.com> wrote:
> In article presence@MUNGEpanix.com says...
>> > Do you happen to know of a little applet that will emulate a one 
> line 
>> > terminal that can be put onto a panel on the desktop (i.e. no standard 
>> > window borders)?  I looked and looked and looked and can't find 
>> 
>> nope.
>> 
>> If you run windows, this is probably a 5 line VB program.
> 
> Does that include a GOTO 10 or  CLR statement?

there's nothing wrong with goto or line numbers.

The only really bad command some basics had was POP
Re: Parse wunderground.com
#130
Author: Mark Anderson
Date: Thu, 06 Dec 2012 22:38
20 lines
2527 bytes
In article presence@MUNGEpanix.com says...
> 
> Mark Anderson <mea@nospambradnylion.com> wrote:
> > In article presence@MUNGEpanix.com says...
> >> > Do you happen to know of a little applet that will emulate a one 
> > line 
> >> > terminal that can be put onto a panel on the desktop (i.e. no standard 
> >> > window borders)?  I looked and looked and looked and can't find 
> >> 
> >> nope.
> >> 
> >> If you run windows, this is probably a 5 line VB program.
> > 
> > Does that include a GOTO 10 or  CLR statement?
> 
> there's nothing wrong with goto or line numbers.
> 
> The only really bad command some basics had was POP

I thought it was the PUSH that did you in.
Re: Parse wunderground.com
#131
Author: Mark Anderson
Date: Fri, 07 Dec 2012 07:45
24 lines
2735 bytes
In article mea@nospambradnylion.com says...
> 
> In article presence@MUNGEpanix.com says...
> > 
> > Mark Anderson <mea@nospambradnylion.com> wrote:
> > > In article presence@MUNGEpanix.com says...
> > >> > Do you happen to know of a little applet that will emulate a one 
> > > line 
> > >> > terminal that can be put onto a panel on the desktop (i.e. no standard 
> > >> > window borders)?  I looked and looked and looked and can't find 
> > >> 
> > >> nope.
> > >> 
> > >> If you run windows, this is probably a 5 line VB program.
> > > 
> > > Does that include a GOTO 10 or  CLR statement?
> > 
> > there's nothing wrong with goto or line numbers.
> > 
> > The only really bad command some basics had was POP
> 
> I thought it was the PUSH that did you in.

oops.  I meant POKE instead of PUSH.   (but facebook patented that).
Re: Parse wunderground.com
#132
Author: Cydrome Leader
Date: Fri, 07 Dec 2012 17:15
30 lines
2615 bytes
Mark Anderson <mea@nospambradnylion.com> wrote:
> In article mea@nospambradnylion.com says...
>> 
>> In article presence@MUNGEpanix.com says...
>> > 
>> > Mark Anderson <mea@nospambradnylion.com> wrote:
>> > > In article presence@MUNGEpanix.com says...
>> > >> > Do you happen to know of a little applet that will emulate a one 
>> > > line 
>> > >> > terminal that can be put onto a panel on the desktop (i.e. no standard 
>> > >> > window borders)?  I looked and looked and looked and can't find 
>> > >> 
>> > >> nope.
>> > >> 
>> > >> If you run windows, this is probably a 5 line VB program.
>> > > 
>> > > Does that include a GOTO 10 or  CLR statement?
>> > 
>> > there's nothing wrong with goto or line numbers.
>> > 
>> > The only really bad command some basics had was POP
>> 
>> I thought it was the PUSH that did you in.
> 
> oops.  I meant POKE instead of PUSH.   (but facebook patented that).

poke and peek were fine. There's nothing wrong with reading or writing to 
memory or devices.

basic haters are people that should not work with computers.
Re: Parse wunderground.com
#133
Author: Mark Anderson
Date: Fri, 07 Dec 2012 22:10
26 lines
2813 bytes
In article presence@MUNGEpanix.com says...
> >> > there's nothing wrong with goto or line numbers.
> >> > 
> >> > The only really bad command some basics had was POP
> >> 
> >> I thought it was the PUSH that did you in.
> > 
> > oops.  I meant POKE instead of PUSH.   (but facebook patented that).
> 
> poke and peek were fine. There's nothing wrong with reading or writing to 
> memory or devices.
> 
> basic haters are people that should not work with computers.

Punch this into your TRS-80

10 PRINT CHR$ (205.5 + RND (1)); : GOTO 10

The following link puts this into context.

http://www.slate.com/articles/technology/books/2012/11/computer_programm
ing_10_print_chr_205_5_rnd_1_goto_10_from_mit_press_reviewed.html


BTW:  IIRC, you could poke into memory you weren't supposed to which 
could cause a system freeze.  
Re: Parse wunderground.com
#135
Author: Robert Bonomi
Date: Sat, 08 Dec 2012 17:16
24 lines
2544 bytes
In article <MPG.2b2ae852b261a80c989a89@news.speakeasy.net>,
Mark Anderson  <mea@nospambradnylion.com> wrote:
>In article presence@MUNGEpanix.com says...
>> 
>> Mark Anderson <mea@nospambradnylion.com> wrote:
>> > In article presence@MUNGEpanix.com says...
>> >> > Do you happen to know of a little applet that will emulate a one 
>> > line 
>> >> > terminal that can be put onto a panel on the desktop (i.e. no standard 
>> >> > window borders)?  I looked and looked and looked and can't find 
>> >> 
>> >> nope.
>> >> 
>> >> If you run windows, this is probably a 5 line VB program.
>> > 
>> > Does that include a GOTO 10 or  CLR statement?
>> 
>> there's nothing wrong with goto or line numbers.
>> 
>> The only really bad command some basics had was POP
>
>I thought it was the PUSH that did you in.

As the prior poster said, it was POP.  (no MOM command :)
Re: Parse wunderground.com
#145
Author: Cydrome Leader
Date: Tue, 11 Dec 2012 20:30
41 lines
2779 bytes
Mark Anderson <mea@nospambradnylion.com> wrote:
> In article presence@MUNGEpanix.com says...
>> >> > there's nothing wrong with goto or line numbers.
>> >> > 
>> >> > The only really bad command some basics had was POP
>> >> 
>> >> I thought it was the PUSH that did you in.
>> > 
>> > oops.  I meant POKE instead of PUSH.   (but facebook patented that).
>> 
>> poke and peek were fine. There's nothing wrong with reading or writing to 
>> memory or devices.
>> 
>> basic haters are people that should not work with computers.
> 
> Punch this into your TRS-80
> 
> 10 PRINT CHR$ (205.5 + RND (1)); : GOTO 10

semicolon colon looks suspect.

this is also a convoluted shitty way to print a slash or back slash. 
whoever write it is a shitty programmer.






> 
> The following link puts this into context.
> 
> http://www.slate.com/articles/technology/books/2012/11/computer_programm
> ing_10_print_chr_205_5_rnd_1_goto_10_from_mit_press_reviewed.html

this is stupid.

> BTW:  IIRC, you could poke into memory you weren't supposed to which 
> could cause a system freeze.  

That's an operating system issue, not a language one.
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads