Created
March 16, 2011 05:03
-
-
Save mattn/872042 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!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