Created
August 15, 2011 15:11
-
-
Save audreyt/1146964 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 5.10.0; | |
use utf8; | |
use LWP::Simple; | |
use Encode 'encode'; | |
use Encode::MIME::Header; | |
use File::Slurp 'slurp'; | |
use Email::MIME; | |
use Email::Sender::Simple qw(sendmail); | |
my $url = "http://www.books.com.tw/exep/prod/books2008/top/best_top_26.php?prev_sub=03"; | |
my $body = get($url); | |
$body =~ m{<h4>.*?<a href="[^"]*">\s*([^<]+?)\s*</a>} or die; | |
return if -d "/tmp/jedi-has-won"; | |
unless (lc($1) eq 'jedi') { | |
binmode STDOUT, ':utf8'; | |
say "==> Top-selling book author is $1, not Jedi; going to poll in another 15 minutes..."; | |
sleep 900; | |
exec($0); | |
exit; | |
} | |
system(wkhtmltoimage => $url => 'screenshot.jpg'); | |
my @parts = ( | |
Email::MIME->create( | |
attributes => { | |
filename => "screenshot.jpg", | |
content_type => "image/jpeg", | |
encoding => "base64", | |
name => "screenshot.jpg", | |
}, | |
body => scalar slurp('screenshot.jpg'), | |
), | |
Email::MIME->create( | |
attributes => { | |
content_type => "text/plain", | |
disposition => "inline", | |
charset => "US-ASCII", | |
}, | |
body => "Congratulations Jedi! " . localtime(), | |
), | |
); | |
my $email = Email::MIME->create( | |
header => [ | |
From => '[email protected]', | |
To => '[email protected]', | |
Cc => '[email protected]', | |
Subject => encode('MIME-B' => "狂賀《簡報原力》登上銷售冠軍"), | |
], | |
parts => [ @parts ], | |
); | |
sendmail($email); | |
say "==> Mail sent to Jedi!"; | |
mkdir "/tmp/jedi-has-won"; | |
exit; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hahahahahah!!!!