#!c:\perl\bin\perl #hcpl.pl: Program to check if you have books due in the near future at Harris #County Public Library and remind you by email if so. #To actually run the script, type the command at DOS prompt # perl thisscript.pl -d3 -e"you@domain.com another@domain.com" -i123456789 -npin -mmail [-pmyproxy[:port]] #This sends you@domain.com and another@domain.com an email about the books due #in 3 days checked out by the person with library card 123456789. The SMTP #mail server is "mail" (most companies use this name). If you have to go through #a proxy server named myproxy to connect to the Internet, append "-pmyproxy" or #"-pmyproxy:8080" to the end (no brackets or quotes; specify port if it's not 80). #If your proxy server additionally requires username/password, uncomment the two #lines below and set them correctly: #$proxyuser="myproxyusername"; #$proxypasswd="myproxypassword"; #This script, as well as hpl.pl is published as freeware at #http://yong321.freeshell.org/freeware/hplhcpl.html #(C) Copyright 2003-2008 Yong Huang (yong321@yahoo.com) #Features common to hcpl.pl and hpl.pl are in header comments of hpl.pl. ########## No need to modify below this line but hacking is welcome. ########## use Net::SMTP; use LWP::UserAgent; use Time::Local; use Getopt::Std; $|=1; getopts('d:e:i:n:m:p:'); if (!defined $opt_d or !defined $opt_e or !defined $opt_i or !defined $opt_n or !defined $opt_m) { print "Usage: perl $0 -d3 -e\"you\@domain.com another\@domain.com\" -i12345678901234 -n1234 -mmail [-pProxy[:port]] -d: from this many days ahead of due date you get email once a day -e: space-separated email addresses the notice will be sent to -i: HCPL library card number -n: card holder's pin number -m: mail server; usually 'mail' but confirm with your system admin -p (optional): proxy server if you have to go through it to access Internet "; exit; } $daysahead=$opt_d; $email=$opt_e; #($email=$opt_e) =~ s/@/\\@/g; $ID=$opt_i; $pin=$opt_n; $mailsrvr=$opt_m; $ProxyServer=$opt_p if defined $opt_p; $ua = new LWP::UserAgent; if (defined $opt_p) { $ua->proxy(http => "http://$ProxyServer"); $ua->env_proxy; } else { $ua->agent("AgentName/0.1"); } #Phase 1 $req = new HTTP::Request 'GET', 'http://catalog.hcpl.net/ipac20/ipac.jsp?session=10F335499F49D.450&profile=hcpl&menu=account&ts=1033354031398&login_prompt=true&lastlogin=1033441743618'; $req->proxy_authorization_basic($proxyuser, $proxypasswd) if defined $proxyuser; { my $cnt=0; sleep 1 while ($cnt++<10 && ($tmp=$ua->request($req)->as_string) eq ""); } #Sometimes this initial connection fails. Try it several times. #print "\n\nPhase 1 output:\n$tmp\n\n\n";#for debugging $tmp =~ /name="session" value="(.*?)"/; $session = $1; #print "Session is: $session\n"; #Phase 2 $req = new HTTP::Request POST => 'http://catalog.hcpl.net/ipac20/ipac.jsp'; $req->proxy_authorization_basic($proxyuser, $proxypasswd) if defined $proxyuser; $req->content_type('application/x-www-form-urlencoded'); $req->content("session=$session&menu=account&aspect=overview&npp=10&ipp=20&profile=hcpl&ri=&sec1=$ID&sec2=$pin"); $ua->request($req); #print "\n\nPhase 2 output:\n", $ua->request($req)->as_string; $ua->request($req)->as_string =~ /Checked Out: (\d+)/; $numbooks = $1; #print "Session: $session and Number of Books: $numbooks\n"; if ($numbooks == 0) { print "You did not check out any books."; exit; } #Phase 3 $req = new HTTP::Request GET => "http://catalog.hcpl.net/ipac20/ipac.jsp?session=$session&profile=hcpl&menu=account&submenu=itemsout"; $req->proxy_authorization_basic($proxyuser, $proxypasswd) if defined $proxyuser; $ua->request($req); #print "\n\nPhase 3 output:\n", $ua->request($req)->as_string; #print "\n---------------------------------\n"; undef $/; $_ = $ua->request($req)->as_string; @line = split /]+>(.*?)[/\.]