Skip to content

Instantly share code, notes, and snippets.

@willwillis
Created December 13, 2009 20:53
Show Gist options
  • Save willwillis/255598 to your computer and use it in GitHub Desktop.
Save willwillis/255598 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
#
# This is a script I used (many years ago) to
# have my paypal balanced texted to me. Srlys doubt it
# still works - and there's prolly an api to call now :/
# (circa early 2000's)
#
use strict;
use warnings;
my $balance = return_balance();
notify_mime($balance) if compare($balance);
sub return_balance {
use WWW::Mechanize;
my $browser = WWW::Mechanize->new();
$browser->get("http://www.paypal.com/");
$browser->form(1);
$browser->field( "login_email", '[email protected]' );
$browser->field( "login_password", 'p4ssw0rd' );
$browser->click();
$browser->follow("click here to reload");
my $html = $browser->content;
$html =~ /(.*history">\$)(\d+\.\d+) (USD)/s;
return $2;
}
sub compare {
use Tie::File;
tie my @balance, 'Tie::File', 'balance.txt' || die $!;
my $new_balance = shift;
my $cur_balance = $balance[0];
$balance[0] = $new_balance;
untie @balance;
return 1 if ( $new_balance ne $cur_balance );
}
sub notify_mime {
use MIME::Lite;
my $msg = MIME::Lite->new(
From => 'Server.com',
To => '[email protected]',
Subject => 'Paypal Balance',
Data => $balance
);
$msg->send || die $!;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment