Skip to content

Instantly share code, notes, and snippets.

@ishiduca
Created June 4, 2011 05:50
Show Gist options
  • Save ishiduca/1007635 to your computer and use it in GitHub Desktop.
Save ishiduca/1007635 to your computer and use it in GitHub Desktop.
illust_id(medium)をGmailで送る
#!/usr/bin/env perl -s
use strict;
use warnings;
use Config::Pit;
use WWW::Pixiv::Download;
use Email::MIME::CreateHTML;
use Email::MIME::CreateHTML::Resolver::CustomUA;
use Email::Send;
use Email::Send::Gmail;
our($log);
my @WARN;
BEGIN {
if ($log) {
$SIG{'__WARN__'} = sub {
push @WARN, shift;
};
}
}
my $illust_id = $ARGV[0] or die qq(usage: $0 [-log] illust_id\n);
my $config = pit_get('www.pixiv.net', require => {
pixiv_id => '', pass => '',
});
die qq(failed: can not "pit_get"\n) if ! %$config;
my $config_gmail = pit_get('gmail.com', require => {
username => '', password => '',
});
die qq(failed: can not "pit_get"\n) if ! %$config;
my $client = WWW::Pixiv::Download->new(
pixiv_id => $config->{pixiv_id},
pass => $config->{pass},
look => $log ? 1 : 0,
);
#my $ua = $client->user_agent;
my $info = $client->prepare_download($illust_id);
#$ua->default_header('Referer' => $client->{referer} );
#$ua->add_handler(request_prepare => sub {
# my($request, $ua, $h) = @_;
# $request->header('Referer' => $client->{referer});
#});
my $resolver = Email::MIME::CreateHTML::Resolver::CustomUA->new({
ua => $client->user_agent,
});
my $email = Email::MIME->create_html(
header => [
From => '[email protected]',
To => '[email protected]',
Subject => 'pixiv catalog' ,
],
#inline_css => 0, # objects がないから設定しない
#embed => 0, # objects がないから設定しない
body => _html_body($info),
resolver => $resolver,
);
my $sender = Email::Send->new({
mailer => 'Gmail',
mailer_args => [
username => $config_gmail->{username},
password => $config_gmail->{password},
]
});
eval { $sender->send($email); };
die qq(Error sending email: "$@") if $@;
if (@WARN) {
my $logfile = "./${illust_id}.log";
open my $fh, '>', $logfile or die qq(can not open "${logfile}".\n);
print $fh @WARN;
close $fh;
}
exit 0;
sub _html_body {
my $info = shift;
my $author_name = $info->{author}->{name};
my $author_link = $info->{author}->{url};
my $title = $info->{title};
my $description = $info->{description} || '';
my $src = $info->{img_src};
my $url = $info->{homepage_url};
(my $html =<<"HTML") =~ tr/\n//d;
<!doctype html>
<body>
<div>
<div>
<h2 style="display:inline;">
<a href="${author_link}" target="_blank">
${author_name}</a></h2> &gt;
<h3 style="display:inline;">
<a href="${url}" target="_blank">${title}</a></h3>
</div>
<p>${description}</p>
<div><a href="${url}" target="_blank"><img src="${src}" />
</a></div>
</div>
</body>
HTML
;
$html;
}
__END__
create pixiv catalog on gmail.
Email::MIME::CreateHTML::Resolver::CustomUA は https://gist.github.com/251646 から
@ishiduca
Copy link
Author

ishiduca commented Jun 5, 2011

  • WWW::Pixiv::Downloadの ver 0.0.4 から 0.0.5 の変更時に、$client->{refefer}に値がある場合、送信時に $request->header(Referer => $client->{referer}) する仕様に改訂したための変更
  • $client->preparer_download のレスポンス(ハッシュリファレンス)の形を改訂したための変更

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment