I use this to send txt messages to my cell when my Paypal balance changes.
#!/usr/bin/perl
# silent11
# 11/16/2004
use strict;
use warnings;
my $paypal_email = "";
my $paypal_pass = "";
my $notify_from = "";
my $notify_to = "";
my $balance_file = "balance.txt";
my $balance = return_balance();
# # # Get notified via email (or cell phone txt msg)
# # # of Paypal balance changes
notify_me( $balance ) if compare( $balance );
# # # Subs # # #
sub return_balance {
use WWW::Mechanize;
my $browser = WWW::Mechanize->new();
$browser->get("https://www.paypal.com/");
$browser->form(1);
$browser->field("login_email", $paypal_email);
$browser->field("login_password", $paypal_pass);
$browser->click();
$browser->follow("click here to reload");
my $html = $browser->content;
# Please don't laugh at the regex ;^) It works!
$html =~ /(.*history">\$)(\d+\.\d+) (USD)/s;
return $2;
}
sub compare {
use Tie::File;
# First time to use Tie::File
# very cool!
tie my @balance, 'Tie::File', $balance_file || die $!;
my $new_balance = shift;
my $cur_balance = $balance[0];
$balance[0] = $new_balance;
untie @balance;
return 1 if ($new_balance != $cur_balance);
}
sub notify_me {
use MIME::Lite;
my $msg = MIME::Lite->new(
From => $notify_from,
To => $notify_to,
Subject => 'Paypal Balance',
Data => $balance
);
$msg->send || die $!;
}
Update: changed http to https per zentra's suggestion.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|