[Omaha.pm] Next meeting: Dec. 16!

Jay Hannah jay at jays.net
Sun Nov 21 06:57:50 CST 2004


Below are the fruits of our labor last Thr. Thanks to everyone that 
came out to help! Feel free to post enhancements if you want the 
continue the tinkering.

Our next meeting is Dec. 16:

    http://omaha.pm.org

j



#!/usr/bin/perl

use Data::Dumper;
use WWW::Mechanize;

my %data;
open (IN, "perl_mongers.xml") or die;
while (<IN>) {
    s/[^ -~]//g;
    chomp;
    if (/<group id/) {
       %data = ();
       ($data{gid}) = (/(\d+)/);
       next;
    }
    my ($ele, $data) = (/<(.*)>(.+)<\/.*>/);
    if ($ele and $data) {
       $data{$ele} = $data;
    }
    if (/<\/location>/ and not defined $data{longitude}) {
       go_fetch(%data);
    }
}


sub go_fetch {
    my (%data) = @_;
    return unless ($data{city} and $data{country});
    #print Dumper %data;
    my $search = "$data{city}, $data{country}";
    print "$search\n";

    my $mech = WWW::Mechanize->new();
    my $url = "http://www.astro.com/atlas/horoscope?submit=Search&";
       # expr=Milpitas%2C+United+States+of+America
    $url .= "expr=$search";
    $url =~ s/ /\+/g;
    $url =~ s/,/\%2C/g;
    #print "$url\n";

    $mech->get( $url );

    #print $mech->content;
    #open (OUT, ">out");
    #print OUT $mech->content;
    #close OUT;
    #print Dumper (split /\n/s, $mech->content);
    #print "\n\n\n\n\n\n=======================";
    my @return = grep { /ade.cgi/ } (split /\n/s, $mech->content);
    #print Dumper @return;
    foreach (@return) {
       s/<.*?>//g;
       conv_latlong($_);
       print "   $_\n";
    }
    exit;
}

sub conv_latlong {
    my ($str) = @_;
    my ($lat, $long) = (/(\d+[ns]\d+).*?(\d+[ew]\d+)/);
    print "[$lat $long]";
    my ($newlat, $newlong);

}



__END__

                 <location>
                         <city>Cascais</city>
                         <state>Lisbon</state>
                         <region>Cascais</region>
                         <country>Portugal</country>
                         <continent>Europe</continent>
                         <longitude></longitude>
                         <latitude></latitude>
                 </location>



More information about the Omaha-pm mailing list