Acme-SDUM-Renew
view release on metacpan or search on metacpan
lib/Acme/SDUM/Renew.pm view on Meta::CPAN
=head1 SYNOPSIS
This module just exports one function wich is responsible
of renew all your books from SDUM. At the end a report
is sent to an email, so you can manually check (yes, manually!)
if the operation suceeded.
use Acme::SDUM::Renew;
sdum_renew($username, $password, $email, $smtp);
=head1 EXPORT
sdum_renew
=head1 FUNCTIONS
=head2 sdum_renew
This is where the magic happens. This function receives the
following parameters:
=over 4
=item username
Username to SDUM (don't forget to prepend a 'A' in case you are a student like me).
=item password
Your super ultra secret password.
=item email
A valid email address to send the report.
=item smtp [optional]
This argument is optional but should be usefull when Mail::Sender defaults
doesn't suit your network configuration. Just pass here the SMTP where
your email are relayed and everything should go smoothly.
=back
=cut
sub sdum_renew {
my ($username, $password, $email, $smtp) = @_;
croak "Username required" unless $username;
croak "Password required" unless $password;
croak "Notification email required" unless $email;
# smtp is optional
my $browser = LWP::UserAgent->new(
requests_redirectable => ['GET', 'HEAD', 'POST']
);
$browser->cookie_jar( {} );
$browser->env_proxy;
# Fase 1: Get the session
lib/Acme/SDUM/Renew.pm view on Meta::CPAN
or die "Content not expected (Phase 4)\n";
# Fase 4: Get login form
$res = $browser->get($1);
$res->is_success or die "Error reading from aleph.sdum.uminho.pt (Phase 4)\n";
my @forms = HTML::Form->parse($res);
my $form = shift @forms;
$form->value('bor_id', $username);
$form->value('bor_verification', $password);
$res = $browser->request($form->click);
$res->is_success or die "Error submiting login form (Phase 4)\n";
# Fase 5: Get Area Pessoal Link
$res->content =~ /rea Pessoal/ or die "Content not expected (check username/password) (Phase 5)\n";
$res->content =~ /href\=\"([^\"]+bor\-info)\"/
or die "Can't find Area Pessoal Link (Phase 5)\n";
$res = $browser->get($1);
$res->is_success or die "Error reading from aleph.sdum.uminho.pt (Phase 5)\n";
# Fase 6: Get Empréstimos Link
$res->content =~ /Irregularidades/ or die "Content not expected (Phase 6)\n";
lib/sdum_renew view on Meta::CPAN
sdum_renew - Command Line interface to Acme::SDUM::Renew
=head1 USAGE
This program is a command line shortcut to the module.
Please run the program without arguments to see the synopsis.
=cut
my $username = shift or usage();
my $password = shift or usage();
my $email = shift or usage();
my $smtp = shift;
sdum_renew($username, $password, $email, $smtp) if $smtp;
sdum_renew($username, $password, $email) unless $smtp;
sub usage {
print <<EOF;
sdum_renew "username" "password" "email" ["smtp"]
This program renews all books on SDUM (www.sdum.uminho.pt).
At the end a report is sent to "email". If you are experiencing
problems, try to pass the "smtp" option with your local relay smtp server.
EOF
exit(1);
}
( run in 0.520 second using v1.01-cache-2.11-cpan-49f99fa48dc )