-
Notifications
You must be signed in to change notification settings - Fork 0
/
youmagic-info.pl
executable file
·75 lines (52 loc) · 2.05 KB
/
youmagic-info.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/perl
use strict;
use LWP::UserAgent;
use Mojo::DOM;
use Switch;
if (!$ARGV[0]) {
print "Usage: $0 (balance|calllog) login password\n";
exit 1;
}
my $ua = LWP::UserAgent->new(cookie_jar => { file => "/tmp/.cookies.$$.txt" });
my $response = $ua->get('https://www.youmagic.com/index.php?option=com_portabillinguser&view=login');
my $dom = Mojo::DOM->new($response->decoded_content) || die;
my %reqhash;
my @inputs = $dom->find("#com-form-login")->[0]->find('input')->each;
foreach my $input (@inputs)
{
next unless $input->attrs->{name};
my $value = $input->attrs->{value};
$value = $ARGV[1] if ($input->attrs->{name} eq 'username');
$value = $ARGV[2] if ($input->attrs->{name} eq 'passwd');
$reqhash{$input->attrs->{name}} = $value;
}
push @{ $ua->requests_redirectable }, 'POST';
$response = $ua->post( 'https://www.youmagic.com/en/component/portabillinguser/', \%reqhash);
switch ($ARGV[0]) {
case 'balance' {
$response = $ua->get( 'https://www.youmagic.com/en/account');
$dom = Mojo::DOM->new($response->decoded_content);
my $balancespan = $dom->find("div.balance-icon")->[0]->content_xml;
my ($balanceval) = ( $balancespan =~ /(\d+\.\d\d) roubles/);
print "$balanceval\n";
}
case 'calllog' {
$response = $ua->get( 'https://www.youmagic.com/en/history');
$dom = Mojo::DOM->new($response->decoded_content);
my $lines = $dom->find("div#dialed div table tr");
my $i=0;
$lines->each(sub {
$i++;
my $status = $_->find("td.f-cld")->[0]->attrs->{class};
my $dest = $_->find("td.f-cld a")->[0]->text,
my $date = $_->find("td.time")->[0]->text; chop($date);
my $time = $_->find("td.time b")->[0]->text;
my $desttype = $_->find("td.destination div")->[0]->text;
my $duration = $_->find("td.duration")->[0]->text;
my $amount = $_->find("td.amount")->[0]->text;
print join("\t",( $i, $status, $dest, $date, $time, $desttype, $duration, $amount ));
print "\n";
});
}
}
END { unlink("/tmp/.cookies.$$.txt"); }