add perl6 implementation
This commit is contained in:
parent
a65bf494b2
commit
064fa399ba
|
|
@ -0,0 +1,30 @@
|
|||
#!/usr/bin/env perl6
|
||||
|
||||
use v6;
|
||||
|
||||
use Net::Telnet; #just a fake module
|
||||
|
||||
my %conf =
|
||||
coffee_machine_ip => '10.10.42.42',
|
||||
password => '1234',
|
||||
password_prompt => 'Password:',
|
||||
delay_before_brew => 17,
|
||||
delay => 24,
|
||||
;
|
||||
|
||||
exit if DateTime.now.day-of-week >= 6;
|
||||
|
||||
my @sessions = grep { /^ <{ $*USER.Str }> <.ws>/ }, run( 'who', :out ).out.lines;
|
||||
|
||||
exit if @sessions.elems == 0;
|
||||
|
||||
sleep %conf<delay_before_brew>;
|
||||
|
||||
my $telnet = Net::Telnet.new( :host( %conf<coffee_machine_ip> ) );
|
||||
$telnet.waitfor( %conf<password_prompt> );
|
||||
$telnet.cmd( %conf<password> );
|
||||
$conn.cmd( 'sys brew' );
|
||||
sleep %conf<delay>;
|
||||
$conn.cmd( 'sys pour' );
|
||||
|
||||
$conn.close;
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
#!/usr/bin/env perl6
|
||||
|
||||
use v6;
|
||||
|
||||
use SMS::Send; #just a fake module
|
||||
|
||||
my %conf =
|
||||
phone_numbers => {
|
||||
my_number => '+15005550006',
|
||||
boss_number => '+xxx',
|
||||
},
|
||||
reasons => [
|
||||
'Locked out',
|
||||
'Pipes broke',
|
||||
'Food poisoning',
|
||||
'Not feeling well',
|
||||
],
|
||||
;
|
||||
|
||||
exit if DateTime.now.day-of-week >= 6;
|
||||
|
||||
my @sessions = grep { /^ <{ $*USER.Str }> <.ws>/ }, run( 'who', :out ).out.lines;
|
||||
|
||||
exit if @sessions.elems > 0;
|
||||
|
||||
my $sender = SMS::Send.new(
|
||||
:twilio,
|
||||
:account-id( %*ENV<TWILIO_ACCOUNT_SID> ),
|
||||
:auth-token( $*ENV<TWILIO_AUTH_TOKEN> ),
|
||||
:from( %conf<phone_numbers><my_number> ),
|
||||
);
|
||||
|
||||
my $sms-text = 'Gonna work from home.' ~ %conf<reasons>.pick;
|
||||
|
||||
my $sent = $sender.send-sms(
|
||||
:text( $sms-text ),
|
||||
:to( %conf<phone_numbers><boss_number> ),
|
||||
);
|
||||
|
||||
say $sent ?? 'Sent message.' !! 'Message failed.';
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
#!/usr/bin/env perl6
|
||||
|
||||
use v6;
|
||||
|
||||
use Gmail; #just a fake module
|
||||
|
||||
my %conf =
|
||||
kumar-email => 'kumar.a@example.com',
|
||||
database_regex => rx /<-space>+ '_staging'/,
|
||||
keywords_regex => rx:i /< sorry help wrong >/,
|
||||
backup_path => '/home/backups/databases/',
|
||||
;
|
||||
|
||||
my $gmail = Gmail.new(
|
||||
:account( %*ENV<GMAIL_USERNAME> ),
|
||||
:password( %*ENV<GMAIL_PASSWORD> );
|
||||
);
|
||||
|
||||
for $gmail.find(:inbox, :unread, :from( %conf<kumar-email> )).lines -> $email {
|
||||
if $email.body.raw-source ~~ %conf<keywords_regex> and ( my $db-name = $email.body.raw-source ~~ %conf<database_regex> ) {
|
||||
my $yesterday = Date.today.pred;
|
||||
my $backup-file = %conf<backup_path> ~ $dbname ~ '-' ~ $yesterday.year ~ $yesterday.month ~ $yesterday.day ~ '.gz';
|
||||
|
||||
die 'ERROR: Backup file not found' if $backup-file.IO !~~ :e;
|
||||
|
||||
shell 'gunzip -c ' ~ $backup-file ~ ' | psql ' ~ $db_name;
|
||||
|
||||
$email.read;
|
||||
$email.label( 'Database fixes' );
|
||||
$gmail.deliver(
|
||||
$gmail.compose(
|
||||
:to( %conf<kumar-email> ),
|
||||
:subject( 'RE: ' ~ $email.subject ),
|
||||
:body( "No problem. I've fixed it. \n\n Please be careful next time." ),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
#!/usr/bin/env perl6
|
||||
|
||||
use v6;
|
||||
|
||||
use SMS::Send; #just a fake module
|
||||
|
||||
my %conf =
|
||||
phone_numbers => {
|
||||
my_number => '+15005550006',
|
||||
her_number => '+xxx',
|
||||
},
|
||||
reasons => [
|
||||
'Working hard',
|
||||
'Gotta ship this feature',
|
||||
'Someone fucked the system again',
|
||||
],
|
||||
;
|
||||
|
||||
exit if DateTime.now.day-of-week >= 6;
|
||||
|
||||
my @sessions = grep { /^ <{ $*USER.Str }> <.ws>/ }, run( 'who', :out ).out.lines;
|
||||
|
||||
exit if @sessions.elems == 0;
|
||||
|
||||
my $sender = SMS::Send.new(
|
||||
:twilio,
|
||||
:account-id( %*ENV<TWILIO_ACCOUNT_SID> ),
|
||||
:auth-token( $*ENV<TWILIO_AUTH_TOKEN> ),
|
||||
:from( %conf<phone_numbers><my_number> ),
|
||||
);
|
||||
|
||||
my $sms-text = 'Late at work.' ~ %conf<reasons>.pick;
|
||||
|
||||
my $sent = $sender.send-sms(
|
||||
:text( $sms-text ),
|
||||
:to( %conf<phone_numbers><her_number> ),
|
||||
);
|
||||
|
||||
say $sent ?? 'Sent message.' !! 'Message failed.';
|
||||
Loading…
Reference in New Issue