Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

AIM-Bot help again, please!

by Sleepaholic88 (Novice)
on Mar 22, 2003 at 03:49 UTC ( [id://245098]=perlquestion: print w/replies, xml ) Need Help??

Sleepaholic88 has asked for the wisdom of the Perl Monks concerning the following question:

Hello, it's me again, the Perl Newbie with the aim-bot =). This time, I want the bot to get a zipcode from the message from the user,
$zip =~ s/\/accuweather //ig;
of course, then it forms this link:
http://beta1.accuweather.com/beta1/dtwx_initialize.asp?zipcode=$zip where $zip, of course, is the zipcode. Then on that page, it finds what is in between <UFDB> and </UFDB> and uses that in this url:
http://beta1.accuweather.com/beta1/dtwx_curcon.asp?ufdb=$ufdb where $ufdb is what it finds in between <UFDB> and </UFDB> in the first site. Then, it finds what is in between different tags in the second page, such as <Temperature></Temperature>, but i guess that it's the same exact thing as finding whats between <UFDB> and </UFDB>. So, my question is: "How do I find what is in the XML tags?" Thanks.

Replies are listed 'Best First'.
Re: AIM-Bot help again, please!
by artist (Parson) on Mar 22, 2003 at 05:19 UTC
    Welcome to the wonderful world of handling XML with perl.

    Observation: Your basic problem is how to parse the XML data and get the desired value for a given tag.
    Pointer:You can use Bundle::XML
    Code:

    use strict; use warnings; use LWP::Simple; use XML::Simple; my $zipcode = '03054'; my $site1 = get 'http://beta1.accuweather.com/beta1/dtwx_initialize.a +sp?zipcode='.$zipcode; my $DTWXSetup = XMLin($site1); my $Location = $DTWXSetup->{Location}; my $UFDB = $Location->{UFDB}; my $site2 = get 'http://beta1.accuweather.com/beta1/dtwx_curcon.asp?u +fdb='.$UFDB; my $CurrentConditions = XMLin($site2); my $Temperature = $CurrentConditions->{Temperature}; print "ZIP:$zipcode\nTemperature:$Temperature\n"; XMLout();
    Few Liner:
    use LWP::Simple; use XML::Simple; my $zipcode = shift; print XMLin(get 'http://beta1.accuweather.com/beta1/dtwx_curcon.asp?uf +db='. XMLin(get 'http://beta1.accuweather.com/beta1/dtwx_initiali +ze.asp?zipcode='.$zipcode)->{Location}->{UFDB})->{Temperature};
    Point: I wish that you will make a point to learn more XML, from sites like XML Perl.

    artist

      It says that $zipcode requires explicit package name. Not exactly sure what that means.... And I would learn some XML, but homework, mostly, keeps me from that =(

        That error means that you are using strict (which is good) and you didn't declare $zipcode with my. If $zipcode is a global variable then put my $zipcode; at the top of your program somewhere. If its in a sub then put my $zipcode; in the sub somewhere before you use it or when you assign it (my $zipcode = ....)

        Hope that helps
        Chris

        Lobster Aliens Are attacking the world!
      Thank you very much!!!! I used the first code, and it worked perfectly! The bot now returns values for:
      Current Condition
      Temperature
      ReelFeel
      Humidity
      UV Index
      Wind Direction and Speed
      Percipitation Thank you very much!
Re: AIM-Bot help again, please!
by DarknessX (Scribe) on Mar 22, 2003 at 20:37 UTC
    IMHO, this entire problem would be more easily solved with Geo::Weather. As soon as you have the zip code, no XML parsing, though I agree completely with point
    -----BEGIN GEEK CODE BLOCK----- Version: 3.1 GPA/P/S d+ s++:+ a--- C++ UL++ P++>++++ L++ E W++ N o? K? w-- !O M- V? + PS++ PE- Y PGP- t 5- X+ R* tv-- b++ !DI D---(+) G e- h-- r++ y? ------END GEEK CODE BLOCK-----

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://245098]
Approved by pfaut
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (2)
As of 2024-04-19 20:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found