Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I wrote two scripts that use German web weather services; both only output to console but they should provide a starting point. One uses regexen to pull out the data (and doesn't work verbatim because their pages seem to frequently move), the other relies on HTML::TableExtract.
#!/usr/bin/perl -w # wetter.pl: gets information from wetter.com use strict; use LWP::Simple; use HTML::Entities; my $city = shift(@ARGV) || die "usage: ./wetter.pl <location>\n\tlocat +ion = Ortsname oder PLZ\n"; $_ = get("http://www.wetter.com/home/structure/control.php?Lang=DE&ms= +1&ss=1&sss=2&search=$city") || die "Dokument konnte nicht uebertragen + werden, keine Informationen verfügbar\n\n"; s/^.*<!-- Content Current -->(.*?)<!-- Additional CONTENT -->.*$/$1/si + || die "Dokument enthaelt keine Wetterdaten\nWahrscheinlich ist der +Suchbegriff wetter.com nicht bekannt\n\n"; my @date = /<div class="headlineHell2">(\d\d\.\d\d\.\d\d\d\d)<br>(\d\d +:\d\d) Uhr Ortszeit<\/div>/si; my @sky = /<span class="tabHeadline">(.*?)<\/span>/si; my @wheather = /<span class="tabBody">(.*?)<\/span>/sgi; decode_entities($_), s/\s+//sg for @date, @sky, @wheather; print << "EOT"; Messung: @date Himmel: @sky Temperatur: @wheather[0,1] Luftdruck: @wheather[2,3] Wind: @wheather[5,6,4] Sicht: @wheather[7,8] EOT
#!/usr/bin/perl -w # yahoowetter: parses weather information from the Yahoo! Wetter servi +ce use strict; use LWP::Simple; use HTML::TableExtract; print "Yahoo! Wetter - Parserskript 0.1 (Stand 3. Jun 2002)\n"; my $URL; if(@ARGV) { $URL = shift @ARGV; } else { open URL, "<", "$ENV{HOME}/.yahoowetter" or die "~/.yahoowetter an +gelegen oder URL auf der Kommandozeile übergeben\n"; $URL = <URL>; close URL; } sub prettify { s/\s+/ /sg, s/^\s+//, s/:?$// for $_[0]; $_[0] } (my $extractor = new HTML::TableExtract)->parse(get($URL) or die "Kein +e Daten geladen (sind wir online?)\n"); my @valuenames = qw(Temperatur Zeitpunkt); my @weather; push @weather, (map [ shift(@valuenames), prettify($_->[0]) ], $extrac +tor->table_state(4,0)->rows()); push @weather, (map [ split(/\W/, prettify($_->[2]), 2) ], $extractor- +>table_state(3,1)->rows()); push @weather, (map [ map prettify($_), @$_ ], $extractor->table_state +(3,2)->rows()); @weather[0,1] = @weather[1,0]; $_->[0] =~ s/$/:/ for @weather; printf "%-20s %s\n", @$_ for @weather; print "\n";

Makeshifts last the longest.


In reply to Re: Weather goest thou, spider? by Aristotle
in thread Weather goest thou, spider? by jens

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-04-19 06:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found