User Control Panel
Advertisements

HELP US, HELP YOU!

Help Needed prasing RSS

 
Post new topic   Reply to topic    Bot Depot Forum Index -> Code Help
View unanswered posts
Author Message
JTW
God Like
God Like


Joined: 07 Mar 2004
Posts: 579
Location: Maidstone
Reputation: 67.1
votes: 4

PostPosted: Wed May 09, 2007 9:18 pm    Post subject: Help Needed prasing RSS Reply with quote

Hi all,

I am working on a new weather command using MSN Weather. So far I know how to get access to the rss feed however I am having trouble prasing it using XML::RSSLite

Here is what i have got working so far

Code:
sub weather {
   my ($bot,$self, $user, $name, $msg, $color) = @_;
   use LWP::Simple;
   if ($msg eq undef){
      $self->sendMessage("You did not include a location");
   }else{
      my $field = {};
         
       $field->{XML} = get( "http://xoap.weather.com/search/search?where=$msg" );
      
      if(!$field->{XML}) {
         $self->sendMessage("Sorry the server seems to be down", Color => b23ce);
         return;
      }
         
      if($field->{XML} =~ m,<loc id="(.*?)",mgo) { $field->{LOCID} = $1; } 
       print "Got LOCATION ID. ($field->{LOCID})" . "\n" . "Getting Weather.";
 
 
        $reply = LWP::Simple::get ("http://weather.msn.com/RSS.aspx?wealocations=wc:$field->{LOCID}&weadegreetype=C");
       $self->sendMessage("$reply");
   }
};
I am aware this just returns the xml but this is as far as I have got working so far. Also I know the code is a mess but I have done my best and would appriciate help fixing and tidying the code.

Thanks

_________________
"Help us, Help you" - BotDepot
Back to top
Teario
Member
Member


Joined: 25 Jun 2004
Posts: 130
Location: Liverpool(home) or Derby(uni), UK
Reputation: 59.8
votes: 3

PostPosted: Sun May 13, 2007 11:05 am    Post subject: Reply with quote

Try this:
Code:
sub weather {
   use LWP::Simple;
   use XML::Simple;

   my ($bot,$self, $user, $name, $msg, $color) = @_;

   if ($msg eq undef){
       $self->sendMessage("You did not include a location");
   }else{
      my $field = {};
         
       $field->{XML} = get( "http://xoap.weather.com/search/search?where=$msg" );
     
      if(!$field->{XML}) {
          $self->sendMessage("Sorry the server seems to be down", Color => b23ce);
         return;
      }
         
      if($field->{XML} =~ m,<loc id="(.*?)",mgo) { $field->{LOCID} = $1; }
       print "Got LOCATION ID. ($field->{LOCID})" . "\n" . "Getting Weather.";
 
 
        $reply = LWP::Simple::get ("http://weather.msn.com/RSS.aspx?wealocations=wc:$field->{LOCID}&weadegreetype=C");
       #$self->sendMessage("$reply");
   
   my $x = XMLin($reply);
   my $f = %{@{$x->{channel}->{item}}[1]}->{description};
   $f =~ s/<[^<]+>//g;
   $f =~ s/°/°/g;
   $f =~ s/%/%\r\n/g;
        $self->sendMessage($f);
   }
};


I have tested it on my computer (not through my bot) and it seems to work fine, with a slight error in showing the degrees sign (it shows a hash sign instead), but I think it should be ok via messenger.

Good luck Smile
~T
Back to top
JTW
God Like
God Like


Joined: 07 Mar 2004
Posts: 579
Location: Maidstone
Reputation: 67.1
votes: 4

PostPosted: Sun May 13, 2007 7:48 pm    Post subject: Reply with quote

Thanks a bunch.
I know why the degree sign isnt working, it is beacuse the code is HTML. However it can easily be fixed by entering 2 lines of code.
The first is
Code:
my $deg = decode_base64("wrA=");
This line can go somewhere near where LWP simple gets the feed from MSN. This second line then swaps the html code for the degree sign.
Code:
   $f =~ s/&\#176;/$deg/ig;

This then goes before the message is sent to the user.

Once Again thanks a lot Smile

_________________
"Help us, Help you" - BotDepot
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Bot Depot Forum Index -> Code Help All times are GMT
Page 1 of 1

 



Protected by phpBB Security phpBB-TweakS
phpBB Security Has Blocked 9 Exploit Attempts.
Antispam Captcha Mod by phpbb-security.com
Powered by phpBB © 2001, 2005 phpBB Group