Skip to content

Instantly share code, notes, and snippets.

@samm-git
Created March 15, 2016 13:40
Show Gist options
  • Select an option

  • Save samm-git/bbae0bb0a375f46e4edd to your computer and use it in GitHub Desktop.

Select an option

Save samm-git/bbae0bb0a375f46e4edd to your computer and use it in GitHub Desktop.
Check balance on CZ kaktus prepaid GSM card
#!/usr/bin/perl
use strict;
require LWP::UserAgent;
# username/password
my $username = '[email protected]';
my $password = 'example';
binmode STDOUT, ":utf8"; # suppress UTF-8 warnings
$ENV{'PERL_LWP_SSL_VERIFY_HOSTNAME'} = 0; # disable ssl checking
# Create a request
my $req = HTTP::Request->new(POST => 'https://www.mujkaktus.cz/.gang/login');
$req->content_type('application/x-www-form-urlencoded');
$req->header('Cookie' => 'COOKIE_SUPPORT=true'); # required
$req->content('username='.$username.'&password='.$password.'&submit=P%C5%99ihl%C3%A1sit');
my $ua = LWP::UserAgent->new;
$ua->cookie_jar( {} ); #
my $response = $ua->request($req);
# status line should be '302 Found' if password is correct
die "Unexpected http response, check login/password\n" if ($response->status_line ne "302 Found");
# we will not follow redirect, but fetch "moje-sluzby" page
$req = HTTP::Request->new(GET => 'https://www.mujkaktus.cz/moje-sluzby');
my $response = $ua->request($req);
if ($response->decoded_content =~ m/stav kreditu<\/h3><div class=\"box-format\"><div id=\"[^"]+\"><p><span class="text-1">([0-9,]+)/i) {
print "Balance: $1 CZK\n";
}
else {
die "Unable to fetch balance data\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment