Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #!/usr/bin/perl
  2.  
  3. use strict;
  4. use LWP::Simple;
  5. use LWP::UserAgent;
  6. use HTTP::Request::Common;
  7. use HTTP::Cookies;
  8.  
  9. my $input       = join(" ",@ARGV);
  10.  
  11. my $mail_addr   = 'dummy@example.co.jp';
  12. my $password    = 'password';
  13.  
  14. my $login_url   = 'https://cp.cocacola.jp/top.php?hn=cp02';
  15. my $regist_url  = 'https://cp.cocacola.jp/serial_regist.php?hn=cp02';
  16.  
  17. my @in = ();
  18. while ($input =~ /^(\d{8})[ \-\.\,]?(\d{8})[ \t]?(.*)$/) {
  19.     push @in,($1.",".$2);
  20.     $input = $3;
  21. }
  22.  
  23. my $ua          = LWP::UserAgent->new;
  24. $ua->cookie_jar(HTTP::Cookies->new(ignore_discard => 1));
  25. my $response    = &process_request($ua,POST($login_url,[ 'id' => $mail_addr, 'password' => $password, 'login[]' => 1 ]));
  26. my $point       = &get_point($response);
  27.  
  28. print "Current           ".$point."\n";
  29.  
  30. foreach my $num(@in) {
  31.     my ($in1,$in2) = split(",",$num);
  32.     print $in1."-".$in2." ";
  33.     $response    = &process_request($ua,POST($regist_url,[ 'serial_1-1' => $in1, 'serial_1-2' => $in2, 'send[]' => 1 ]));
  34.     $point       = &get_point($response);
  35.     print $point."\n";
  36. }
  37.  
  38.  
  39.  
  40. sub process_request {
  41.     my ($ua, $request) = @_;
  42.     my $res = $ua->request($request);
  43.     while ($res->is_redirect) {
  44.         my $url = $res->header('Location');
  45.         $res = $ua->request(HTTP::Request->new(GET => $url));
  46.     }
  47.     return $res;
  48. }
  49.  
  50. sub get_point {
  51.     my ($response) = @_;
  52.     my $res = "";
  53.     if ($response->content =~ /\<dd id\=\"currentPoint\"\>\<span\>(.*?)\<\/span\>\<\/dd\>/) {
  54.         $res = $1;
  55.     }
  56.     $res;
  57. }