-
Notifications
You must be signed in to change notification settings - Fork 0
/
whisper.pl
63 lines (50 loc) · 1.17 KB
/
whisper.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/perl -w
# whisper.pl
#
# A simple and awesome utility to send documents to a Kindle.
package Whisper;
use strict;
use warnings;
use Data::Dumper;
use Getopt::Long;
use YAML::Tiny;
use Try::Tiny;
use Log;
use Amazon::SendToKindle;
# Prints the help message.
sub HelpMessage {
print "whisper [options] file\n";
}
# Prints the version message.
sub VersionMessage {
print "Whisper v0.1\n";
}
# Setup Getopt.
my ($convert, $account, $file);
GetOptions("convert|c" => \$convert,
"account|a=s" => \$account,
"file|f=s" => \$file);
# Read the config fie.
my $config = YAML::Tiny->new();
$config = YAML::Tiny->read("config.yml");
my $email = $config->[0]->{email};
# Setup the Kindle and send.
my $kindle = Amazon::SendToKindle->new(
$file,
$email->{address},
$email->{smtp_server},
$email->{port},
$email->{username},
$email->{password});
# Setup logging.
my $log = new Whisper::Log();
# Send the document.
try {
$kindle->send($account, $convert);
# Log the action.
$log->send($file, $account, $convert, "Sent");
} catch {
# Log the error.
$log->send($file, $account, $convert, "Failed");
print "There was an error while trying to send the document: $_";
};