Skip to content

Commit 3bcd684

Browse files
committed
Add perl/smack-my-bitch-up.pl
Dependencies: - DateTime - SMS::Send::Twilio - YAML
1 parent 1366360 commit 3bcd684

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

perl/smack-my-bitch-up.pl

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/usr/bin/perl
2+
3+
use strict;
4+
use warnings;
5+
6+
use DateTime;
7+
use SMS::Send;
8+
use YAML;
9+
10+
# Config
11+
my $conf = Load( <<'...' );
12+
---
13+
phone_numbers:
14+
my_number: +15005550006
15+
her_number: +xxx
16+
reasons:
17+
- Working hard
18+
- Gotta ship this feature
19+
- Someone fucked the system again
20+
...
21+
22+
my $date = DateTime->now;
23+
24+
# Skip on weekends
25+
if ( $date->day_of_week >= 6 ) {
26+
exit;
27+
}
28+
29+
# Exit early if no sessions with my username are found
30+
open( my $cmd_who, '-|', 'who' ) || die "Cannot pipe who command ". $!;
31+
32+
my @sessions = grep {
33+
m/$ENV{'USER'}/
34+
} <$cmd_who>;
35+
36+
close $cmd_who;
37+
38+
exit if ( scalar( @sessions ) == 0 );
39+
40+
# Load Twilio API config
41+
open( my $env, '<', '../.env' ) || die "Cannot find .env file in project root.";
42+
LINE: while ( my $line = <$env> ) {
43+
next LINE unless ( $line =~ m/^(TWILIO[^=]+)=(.*)(?:[\n\r]*)/ );
44+
$conf->{'env'}->{ $1 } = $2;
45+
}
46+
47+
close $env;
48+
49+
# Randomize excuse
50+
my $reason_number = int( rand( scalar( @{ $conf->{'reasons'} } ) ) );
51+
my $sms_text = "Late at work. ". $conf->{'reasons'}[ $reason_number ];
52+
53+
# Create an object. There are three required values:
54+
my $sender = SMS::Send->new('Twilio',
55+
_accountsid => $conf->{'env'}->{'TWILIO_ACCOUNT_SID'},
56+
_authtoken => $conf->{'env'}->{'TWILIO_AUTH_TOKEN'},
57+
_from => $conf->{'phone_numbers'}->{'my_number'},
58+
);
59+
60+
# Send a message to me
61+
my $sent = $sender->send_sms(
62+
text => $sms_text,
63+
to => $conf->{'phone_numbers'}->{'her_number'},
64+
);
65+
66+
# Did it send?
67+
if ( $sent ) {
68+
print "Sent message.\n";
69+
} else {
70+
print "Message failed.\n";
71+
}
72+

0 commit comments

Comments
 (0)