urn:earthquake-usgs-gov:us:c000hkbeM 4.9 - 71km SW of Paita, Peru2013-06-10T16:39:37.373ZDYFI? - I
Time
2013-06-10 14:21:17 UTC
2013-06-10 09:21:17 -05:00 at epicenter
Location
5.545°S 81.572°W
Depth
47.92 km (29.78 mi)
]]>
-5.5453 -81.5723-47920
####
#!/usr/bin/perl -w
use XML::FeedPP;
use XML::LibXML;
use XML::Rules;
use LWP::Simple;
use strict;
use warnings;
# get the Atom feed from the USGS
my $source = 'http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/4.5_day.atom';
my $feed = XML::FeedPP->new( $source );
# Incorporating a rules section so that we can extract the information from the CDATA section
# and any other specific fields we might need. First attempt will be to pull the 'Updated'
# field data from the Atom feed. I tried to follow the example in the CPAN summary but I'm
# clearly lost.
my @rules = (
_default => sub {$_[0] => $_[1]->{_content}},
id => sub {$_[0] => $_[1]->{_content}},
author => undef, # ignorning the author because I already know it's the USGS
updated => sub {print "$_[1]->{updated}\n";
},
);
my $parser = XML::Rules->new(rules => \@rules);
$parser->parse( $feed );
# This section extracts the title field, then performs string manipulations to extract the
# long location data and the magnitude. Funny that USGS does not have a magnitude field
# in this feed.
foreach my $quake( $feed->get_item() ) {
my $title = $quake->title();
my $place = substr($title, 8);
my $magnitude = substr($title, 2,3);
# my $id = $quake->get( $id ); # note that my attempt to get field data did not work.
# my $update = $quake->updated();
# my $location = $quake->'georss:point'();
print "Magnitude ", $magnitude, " about ", $place, "\n";
}