Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use strict;
- use WWW::Mechanize;
- use File::Path;
- ########################################################################################################################
- # Change only the configuration settings in this section, nothing above or below it. #
- ########################################################################################################################
- # Credentials
- my $username = "someone";
- my $password = "somepassword";
- # Enclose value in double quotes, folders with spaces in the name are ok.
- my $root_folder = "/Users/john/Documents/Personal/Utilities/Sprint/";
- # Numeric account number, change to match yours
- my $account = "874000001";
- ########################################################################################################################
- ########################################################################################################################
- # Suddenly web robot.
- my $mech = WWW::Mechanize->new();
- $mech->agent_alias('Mac Safari');
- # Base URL for PDF statements.
- $mech->get("http://mysprint.sprint.com/mysprint/pages/sl/global/login.jsp");
- # Login, blah.
- $mech->submit_form(
- form_id => 'frmUserLoginDL',
- fields => { USER => $username,
- PASSWORD => $password,
- },
- );
- # Dumb thing uses a meta refresh...
- $mech->follow_link(url_regex => qr/CollectDevicePrint\.do/);
- # Now a magic bounce...
- my $pm_fp = "version=1&pm_fpua=mozilla/5.0 (macintosh; intel mac os x 10_9_3) applewebkit/537.36 (khtml, like gecko) " .
- "chrome/35.0.1916.153 safari/537.36|5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.36 (KHTML, " .
- "like Gecko) Chrome/35.0.1916.153 Safari/537.36|MacIntel&pm_fpsc=24|1920|1200|1178&pm_fpsw=&pm_fptz=-6" .
- "&pm_fpln=lang=en-US|syslang=|userlang=&pm_fpjv=1&pm_fpco=1";
- foreach my $form ($mech->forms()) {
- map { $_->readonly(0) } $form->inputs();
- }
- $mech->submit_form(
- form_name => 'LoginForm',
- fields => { pm_fp => $pm_fp },
- );
- # Another meta refresh...
- $mech->follow_link(url_regex => qr/ReturnToCaller\.do/);
- # Another magic form bounce...
- $mech->submit_form(
- form_name => 'CallbackForm',
- );
- # Get the initial bill page.
- $mech->get("https://myaccountportal.sprint.com/servlet/ecare?inf_action=login&action=accountBill&sl=111100&selaccount=$account");
- # Finally we can get to the billing history page.
- $mech->get("https://myaccountportal.sprint.com/servlet/ecare?inf_action=downloadDates&isBillHist=true");
- my $page = $mech->content();
- # Now we need to get all PDF links. Jackasses didn't put direct links, javascript constructs them onclick. Some of them
- # are just "billImage", but others are "billImageFromOlive" ... no idea of the difference.
- while ($page =~ /(\/servlet\/ecare\?inf_template=\/servlet\/billImage(?:FromOlive)*\?billDate=)(\d\d)\/(\d\d)\/(\d{4})/g) {
- # Extract the date.
- my $year = $4;
- my $date = "$year-$3-$2";
- my $link = "$1$2/$3/$year";
- # This will create any nested directories necessary. Mostly for the year.
- File::Path::make_path("$root_folder$year");
- # Does the YYYY-MM-DD.pdf file exist?
- unless (-f "$root_folder$year/$date.pdf") {
- # We need a copy of the $mech object.
- my $pdf = $mech->clone();
- $pdf->get($link, ':content_file' => "$root_folder$year/$date.pdf");
- # Let's do a notification...
- #system("/usr/local/bin/terminal-notifier -message \"Sprint document dated $date has been downloaded.\" -title \"Statement Retrieved\" ");
- }
- }
- # It seems possible to get statements that aren't listed on the history page. Let's see if we can let them grab those
- # too. Note: These only seem to go back to about 2007, always seem to use the 1st for the day of month. Runs forever,
- # comment out again after you've grabbed them.
- # if (1) {
- # for (my $year = 2008; $year--; $year > 2007) {
- # for my $month ("01" .. "12") {
- # #for () {
- # my $date = "$year-$month-01";
- # # This will create any nested directories necessary. Mostly for the year.
- # File::Path::make_path("$root_folder$year");
- # unless (-f "$root_folder$year/$date.pdf") {
- # # Need to clone it.
- # my $pdf = $mech->clone();
- # my $filepath = "$root_folder$year/$date.pdf";
- # my $link = "/servlet/ecare?inf_template=/servlet/billImageFromOlive?billDate=01/$month/$year";
- # $pdf->get($link, ':content_file' => $filepath);
- # # Check that it was successful. Always get a 200 response code, so we'll check mimetype for app/pdf.
- # if ($pdf->ct() ne "application/pdf") { unlink $filepath; print "Nothing for $date\n"; }
- # else { print "Found $date\n"; }
- # }
- # #}
- # }
- # }
- # }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement