Perlで日の出・日の入(日没)の時刻と天気予報をメールでRemember The Milkに登録 (1/13)
「Perlで日の出・日の入(日没)の時刻をメールでRemember The Milkに登録 (1/13)」
P.S.
あとは天気予報も埋め込めたら便利かも。
ということで作ってみました。汚くてごめんなさい。
#!/usr/local/bin/perl
use strict;
use warnings;my $from = '***@nifty.com';
my $to = '***@rmilk.com';
my $cc = '***@nifty.com';
my $keido = 139.5;
my $ido = 35.5;my ($sub,$mes_sunrise) = &sunrise_sunset($keido,$ido);
my $mes_weather = &weather();
my @mes = ( $mes_sunrise, $mes_weather );
&sendmail($sub,@mes);exit 1;
sub sunrise_sunset {
use Astro::Sunrise;
use Date::Simple;my ($keido,$ido) = @_;
my $sunrise = sun_rise( $keido, $ido );
my $sunset = sun_set( $keido, $ido);my $today = Date::Simple->new;
my $day_of_week = ('Sun','Mon','Tue','Wed','Thu','Fri','Sat')[$today->day_of_week];
my $today_week = "$today $day_of_week";my $mailbody = <<_MAIL_BODY_;
List: Calendar
Due: $today $sunrise
---
$today_week
Sunrise: $sunrise
Sunset: $sunset
---
_MAIL_BODY_my $subject = "$today_week Sunrise: $sunrise, Sunset: $sunset";
return ($subject,$mailbody);
}sub weather {
use WebService::Livedoor::Weather;
use Unicode::Japanese;my $lwws = WebService::Livedoor::Weather->new();
my $city = '65'; # Tokyo
my $ret_today = $lwws->get($city,'today');
my $ret_tomorrow = $lwws->get($city,'tomorrow');my $weather = <<_WEATHER_;
$ret_today->{title}
$ret_today->{telop}
$ret_today->{description}$ret_tomorrow->{title}
$ret_tomorrow->{telop}
-end-
_WEATHER_my $weather_jp = Unicode::Japanese->new($weather)->euc;
return $weather_jp;
}sub sendmail {
use Net::SMTP;
my $smtp = Net::SMTP->new('smtp.nifty.com');
my $subject = $_[0];
my $mailbody = "$_[1]$_[2]";$smtp -> mail($from);
$smtp -> to($to);
$smtp -> cc($cc);$smtp -> data();
$smtp -> datasend("From:$from\n");
$smtp -> datasend("To:$to\n");
$smtp -> datasend("Cc:$cc\n");
$smtp -> datasend("Subject:$subject\n");
$smtp -> datasend("\n");
$smtp -> datasend("$mailbody\n");
$smtp -> dataend();
$smtp -> quit;
}
以上。
| 固定リンク | コメント (0) | トラックバック (0)


