Advertisement
NoMoreNicksLeft

sprint

Jul 10th, 2014
683
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 4.81 KB | None | 0 0
  1. #!/usr/bin/perl
  2. use strict;
  3.  
  4. use WWW::Mechanize;
  5. use File::Path;
  6.  
  7. ########################################################################################################################
  8. #                Change only the configuration settings in this section, nothing above or below it.                    #
  9. ########################################################################################################################
  10.  
  11. # Credentials
  12. my $username = "someone";
  13. my $password = "somepassword";
  14.  
  15. # Enclose value in double quotes, folders with spaces in the name are ok.
  16. my $root_folder = "/Users/john/Documents/Personal/Utilities/Sprint/";
  17.  
  18. # Numeric account number, change to match yours
  19. my $account  = "874000001";
  20.  
  21. ########################################################################################################################
  22. ########################################################################################################################
  23.  
  24. # Suddenly web robot.
  25. my $mech = WWW::Mechanize->new();
  26. $mech->agent_alias('Mac Safari');
  27.  
  28. # Base URL for PDF statements.
  29. $mech->get("http://mysprint.sprint.com/mysprint/pages/sl/global/login.jsp");
  30.  
  31. # Login, blah.
  32. $mech->submit_form(
  33.   form_id => 'frmUserLoginDL',
  34.   fields  => { USER     => $username,
  35.                PASSWORD => $password,
  36.              },
  37. );
  38.  
  39. # Dumb thing uses a meta refresh...
  40. $mech->follow_link(url_regex => qr/CollectDevicePrint\.do/);
  41.  
  42. # Now a magic bounce...
  43. my $pm_fp = "version=1&pm_fpua=mozilla/5.0 (macintosh; intel mac os x 10_9_3) applewebkit/537.36 (khtml, like gecko) " .
  44.             "chrome/35.0.1916.153 safari/537.36|5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.36 (KHTML, " .
  45.             "like Gecko) Chrome/35.0.1916.153 Safari/537.36|MacIntel&pm_fpsc=24|1920|1200|1178&pm_fpsw=&pm_fptz=-6" .
  46.             "&pm_fpln=lang=en-US|syslang=|userlang=&pm_fpjv=1&pm_fpco=1";
  47. foreach my $form ($mech->forms()) {
  48.     map { $_->readonly(0) } $form->inputs();
  49. }
  50. $mech->submit_form(
  51.   form_name => 'LoginForm',
  52.   fields    => { pm_fp => $pm_fp },
  53. );
  54.  
  55. # Another meta refresh...
  56. $mech->follow_link(url_regex => qr/ReturnToCaller\.do/);
  57.  
  58. # Another magic form bounce...
  59. $mech->submit_form(
  60.   form_name => 'CallbackForm',
  61. );
  62.  
  63. # Get the initial bill page.
  64. $mech->get("https://myaccountportal.sprint.com/servlet/ecare?inf_action=login&action=accountBill&sl=111100&selaccount=$account");
  65.  
  66. # Finally we can get to the billing history page.
  67. $mech->get("https://myaccountportal.sprint.com/servlet/ecare?inf_action=downloadDates&isBillHist=true");
  68. my $page = $mech->content();
  69.  
  70. # Now we need to get all PDF links. Jackasses didn't put direct links, javascript constructs them onclick. Some of them
  71. # are just "billImage", but others are "billImageFromOlive" ... no idea of the difference.
  72. while ($page =~ /(\/servlet\/ecare\?inf_template=\/servlet\/billImage(?:FromOlive)*\?billDate=)(\d\d)\/(\d\d)\/(\d{4})/g) {
  73.     # Extract the date.
  74.     my $year = $4;
  75.     my $date = "$year-$3-$2";
  76.     my $link = "$1$2/$3/$year";
  77.  
  78.     # This will create any nested directories necessary. Mostly for the year.
  79.     File::Path::make_path("$root_folder$year");
  80.  
  81.     # Does the YYYY-MM-DD.pdf file exist?
  82.     unless (-f "$root_folder$year/$date.pdf") {
  83.         # We need a copy of the $mech object.
  84.         my $pdf = $mech->clone();
  85.         $pdf->get($link, ':content_file' => "$root_folder$year/$date.pdf");
  86.         # Let's do a notification...
  87.         #system("/usr/local/bin/terminal-notifier -message \"Sprint document dated $date has been downloaded.\" -title \"Statement Retrieved\" ");
  88.  
  89.     }
  90. }
  91.  
  92. # It seems possible to get statements that aren't listed on the history page. Let's see if we can let them grab those
  93. # too. Note: These only seem to go back to about 2007, always seem to use the 1st for the day of month. Runs forever,
  94. # comment out again after you've grabbed them.
  95. # if (1) {
  96. #   for (my $year = 2008; $year--; $year > 2007) {
  97. #     for my $month ("01" .. "12") {
  98. #       #for () {
  99. #         my $date = "$year-$month-01";
  100.  
  101. #          # This will create any nested directories necessary. Mostly for the year.
  102. #          File::Path::make_path("$root_folder$year");
  103.  
  104. #         unless (-f "$root_folder$year/$date.pdf") {
  105. #           # Need to clone it.
  106. #           my $pdf = $mech->clone();
  107. #           my $filepath = "$root_folder$year/$date.pdf";
  108. #           my $link = "/servlet/ecare?inf_template=/servlet/billImageFromOlive?billDate=01/$month/$year";
  109. #           $pdf->get($link, ':content_file' => $filepath);
  110. #           # Check that it was successful. Always get a 200 response code, so we'll check mimetype for app/pdf.
  111. #           if ($pdf->ct() ne "application/pdf") { unlink $filepath; print "Nothing for $date\n"; }
  112. #           else { print "Found $date\n"; }
  113. #         }
  114. #       #}
  115. #     }
  116. #   }
  117. # }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement