647cb3493e2dbd664ed1157cab06e72a808a3ff9
[sms.git] / sms.pl
1 #!/usr/bin/env perl
2
3 use strict;
4 use warnings;
5
6 use WWW::Mechanize;
7 use Mojo::DOM;
8 use Config::General;
9 use Data::Dumper;
10
11 #Usage:
12 # sms.pl MOBILE_NO "TEXT_MESSAGE"
13 #
14 # You need to set sms.conf file in the scripts directory and fill it
15 # like this:
16 # login    LOGIN
17 # password PASSWORD
18 #
19 # where LOGIN and PASSWORD are your credentials to orange.pl site
20
21 my $conf = new Config::General("sms.conf");
22 my %config = $conf->getall;
23 die "No login in config file. Stopped" unless $config{login};
24 die "No password in config file. Stopped" unless $config{password};
25
26 my $number = $ARGV[0];
27 my $message = $ARGV[1];
28 die "No recipient number entered. Stopped" unless $number;
29 die "No message entered. Stopped" unless $message;
30
31 my $mech = WWW::Mechanize->new;
32 $mech->get("http://orange.pl");
33 $mech->submit_form(
34     form_id => 'loginForm',
35     fields => {
36         '/tp/core/profile/login/ProfileLoginFormHandler.value.login' => $config{login},
37         '/tp/core/profile/login/ProfileLoginFormHandler.value.password' => $config{password}
38     }
39   );
40 $mech->follow_link( text => 'SMS');
41
42 my $dom = Mojo::DOM->new;
43 $dom->parse($mech->content());
44
45 my $send_url = $dom->find('div[id="top-buttons"] a')->[1]->attrs('href');
46 $mech->get($send_url);
47
48 # Using $mech->submit_form instead is not working, so don't change
49 # code below!
50 $mech->form_name('sendSMS');
51 $mech->set_fields(
52     '/amg/ptk/map/messagebox/formhandlers/MessageFormHandler.to' => $number,
53     '/amg/ptk/map/messagebox/formhandlers/MessageFormHandler.body' => $message,
54 );
55 $mech->click();
56
57 $dom->parse($mech->content());
58
59 my $free_sms_left = $dom->find('div[id="syndication"] p span')->[1]->text;
60
61 print "Message has been sent. Free sms'es left: $free_sms_left\n";