ESN 71466-080107-631798-42


Document Name: Perl script to get Numly
Document Description: Perl script to get Numly

Perl script to get Numly


2008/01/08

Following up on Numly tags help protect your digital content, I wrote a Perl script to fetch Numly ESN's.

I have this script create a ".numly" file in the same directory as the original page; my page display code notices if that file exists and display it if it does.

So, for example, to create the Numly data for this page, I'd run "getesn.pl http://aplawrence.com/Programming/numly_tags.html" and that will create "/Programming/numly_tags.numly" in the appropriate pace.

I didn't put a lot of error checking in here, and of course you'd need to modify it for your own particular needs.

See LWP and POST and GET for more on using Perl LWP.

 #!/usr/bin/perl
 # Numly esn getter
 # A.P. Lawrence 2008/01/07
 # POST method form
 use HTTP::Request::Common qw(POST);
 use LWP::UserAgent;
 $webdir-="/you/live/somewhere";
 chdir($webdir) or exit 1;
 #
 $url=shift @ARGV;
 chomp $url;
 $myfile=$url;
 $myfile=~ s/http.*aplawrence.com.//;
 # you'd be trimming your domain
 $numly=$myfile;
 $numly=~ s/.html$/.numly/;
 if (-e $numly) {
   print "$numly exists!";exit 1;
 #}
 open(I,"$myfile");
 @description=<I>;close I;
 $description= join " ",@description;
 foreach (@description) {
   chomp;
   last if $docname;
   # this section will probablt be different for you
   if (/<h1>/) {
     s/<h1>//;
     $docname=$_;
     $docname=~ s/.*bookmark">//;
     $docname=~ s/<.*//;
   }
 }
  if (not $docname) {
   print "No docname!\n";
   exit 1;
 }
 
 
 # ready to go get it
 $ua=LWP::UserAgent->new();
 my $req= POST 'http://www.numly.com/numly/generate.asp', [
 username => 'pcunix',
 docname => $docname,
 docdesc => $description,
 author => 'Anthony Lawrence',
 publisher => 'Anthony Lawrence',
 licensee => 'Anthony Lawrence',
 licemail => 'pcunix at gmail.com',
 idonly => 'True',
 url => $url];
 #
 $result=$ua->request($req)->as_string; 
 @stuff = split /\n/,$result;
 $content=$stuff[$#stuff];
 $ID=$content;
 $FID=$ID;
 $FID=~ s/(......)(......)(..)$/-$1-$2-$3/;
 #
 print $content; 
 $ID=~s/.* //;
 open(O,">$numly");
 print O <<EOF;
 <p><a href="http://www.numly.com/numly/verify.asp?id=$FID"><img alt="numly esn" src="http://numly.com/numly/icon.asp?id=$ID" border="0" /> $FID<br /><img alt="numly barcode" src="http://numly.com/numly/barcode.asp?code=$ID&height=20&width=1&mode=code39" /></a><br><br>© 2008 All Rights Reserved.</p>
 EOF
 close O;
 exit 0;
 

Author: Anthony Lawrence - Contact Author
Publisher: Anthony Lawrence
Licensee Name: Anthony Lawrence
Reference URL: http://aplawrence.com/Programming/numly_tags.html
Copyright: All Rights Reserved
Registration Date: 1/8/2008 12:18:31 AM UTC
Views: 326




NUMLY.COM