Skip to content

Instantly share code, notes, and snippets.

@yseto
Created March 20, 2013 14:44
Show Gist options
  • Save yseto/5205200 to your computer and use it in GitHub Desktop.
Save yseto/5205200 to your computer and use it in GitHub Desktop.
風が吹けば桶屋が儲からないようにするためのスクリプト
#!/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