Last active
December 25, 2015 08:58
-
-
Save soh-i/6950202 to your computer and use it in GitHub Desktop.
群像で綿矢りさが新しい作品書いたか分かるやつ
This file contains 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
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use utf8; | |
use Encode; | |
use File::Which; | |
use LWP::UserAgent; | |
use HTML::TreeBuilder; | |
if (which("terminal-notifier")) { | |
find_from_gunzo(); | |
} else { | |
die "gem install terminal-notifier"; | |
} | |
sub find_from_gunzo { | |
my $url = 'http://gunzo.kodansha.co.jp/'; | |
my $user_agent = 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_3; en-US)'; | |
my $ua = LWP::UserAgent->new(agent=>$user_agent); | |
my $res = $ua->get($url); | |
if ($res->is_success) { | |
my $content = $res->content(); | |
my $tree = HTML::TreeBuilder->new(); | |
$tree->parse($content); | |
for my $pick_up_title ($tree->look_down('class', 'contents')->find('p')) { | |
my $title = $pick_up_title->as_text(); | |
if (_is_wataya($title)) { | |
my $n_title = encode_utf8("群像から新作お知らせ"); | |
system("terminal-notifier -message $title -title $n_title >/dev/null"); | |
} | |
} | |
} else { | |
die $res->status_line(); | |
} | |
} | |
sub _is_wataya { | |
my $c = shift; | |
my $ma = encode_utf8('綿矢りさ'); | |
if ($c =~ m/$ma/g) { | |
return 1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment