Created
March 20, 2013 14:44
-
-
Save yseto/5205200 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 5.12.1; | |
use utf8; | |
use Email::Sender::Simple qw(sendmail); | |
use Email::Simple; | |
use Email::Simple::Creator; | |
use Data::Recursive::Encode; | |
use Encode; | |
use Email::Sender::Transport::SMTP::TLS; | |
use Web::Scraper; | |
use URI; | |
sub scrapeyjpn { | |
my $uri = URI->new( | |
"http://weather.yahoo.co.jp/weather/jp/**/****/*****/*******.html"); | |
my $scraper = scraper { | |
process '//div[@class="warning-txt yjSt"]', 'l' => 'TEXT'; | |
process | |
'//div[@id="yjw_pinpoint_tomorrow"]/table[@class="yjw_table2"]/tr[1]/td', | |
'h[]' => 'TEXT'; | |
process | |
'//div[@id="yjw_pinpoint_tomorrow"]/table[@class="yjw_table2"]/tr[6]/td', | |
'p[]' => 'TEXT'; | |
return 'l', 'p'; | |
}; | |
my $result = $scraper->scrape($uri); | |
my @h = @{ $result->{h} }; | |
my @p = @{ $result->{p} }; | |
my $content = ""; | |
$content .= $result->{l}; | |
$content .= "\n"; | |
foreach my $i ( 1 .. 8 ) { | |
$content .= $h[$i] . "\t" . $p[$i] . "\n"; | |
} | |
$content; | |
} | |
my $sender = Email::Sender::Transport::SMTP::TLS->new( | |
host => '*******************', | |
port => 587, | |
username => '******************************', | |
password => '*************', | |
helo => '********************', | |
); | |
my $email = Email::Simple->create( | |
header => Data::Recursive::Encode->encode( | |
'MIME-Header-ISO_2022_JP' => [ | |
To => '"****" <****************@gmail.com>', | |
From => '"**" <******************************>', | |
Subject => "明日の天気 by Yahoo Japanの天気", | |
] | |
), | |
body => encode( 'iso-2022-jp', &scrapeyjpn ), | |
attributes => { | |
content_type => 'text/plain', | |
charset => 'ISO-2022-JP', | |
encoding => '7bit', | |
}, | |
); | |
sendmail( $email, { transport => $sender } ); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment