Skip to content

Instantly share code, notes, and snippets.

@mattn
Created March 16, 2011 05:03
Show Gist options
  • Save mattn/872042 to your computer and use it in GitHub Desktop.
Save mattn/872042 to your computer and use it in GitHub Desktop.
#!perl
# 使う場合はこっちね: https://github.com/mattn/earthquake-growler
use strict;
use warnings;
use utf8;
use XML::Feed;
use XML::Feed::Deduper;
use Growl::Any;
use File::Temp qw/ tempfile /;
my $uri = 'http://tenki.jp/component/static_api/rss/earthquake/recent_entries_by_day.xml';
my $growl = Growl::Any->new( appname => '地震速報', events => ['地震'] );
my ( $fh, $temp ) = tempfile();
close $fh;
my $deduper = XML::Feed::Deduper->new( path => $temp );
while (1) {
my $feed = XML::Feed->parse( URI->new($uri) )
or die $growl->notify( 'Error', 'fetch feed', XML::Feed->errstr );
if ($feed) {
for my $entry ( $deduper->dedup( $feed->entries ) ) {
my $title = $entry->title;
my $description = $entry->content->body;
$description =~ s/<[^>]*>//sg;
$growl->notify( '地震', $title, $description );
}
}
sleep 30;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment