APLawrence - Information and Resources for Unix and Linux Systems, Bloggers and the self-employed
RSS Feeds Get APLawrence.com by RSS











(OLDER) <- More Stuff -> (NEWER) (NEWEST)
Home > Programming > Perl script to get Numly
Printer Friendly Version






Perl script to get Numly


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 displays 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 place.

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 probably 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; 
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;
 

If this page was useful to you, please click to help others find it:  
Your +1's can help friends, contacts, and others on the web find the best stuff when they search.


Comments?




More Articles by Anthony Lawrence - Find me on Google+



Click here to add your comments



Don't miss responses! Subscribe to Comments by RSS or by Email

Click here to add your comments


If you want a picture to show with your comment, go get a Gravatar


Kerio Connect Mailserver

Kerio Control Firewall

Have you tried Searching this site?

Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more. We appreciate comments and article submissions.

Publishing your articles here

Jump to Comments



Many of the products and books I review are things I purchased for my own use. Some were given to me specifically for the purpose of reviewing them. I resell or can earn commissions from the sale of some of these items. Links within these pages may be affiliate links that pay me for referring you to them. That's mostly insignificant amounts of money; whenever it is not I have made my relationship plain. I also may own stock in companies mentioned here. If you have any question, please do feel free to contact me.

Specific links that take you to pages that allow you to purchase the item I reviewed are very likely to pay me a commission. Many of the books I review were given to me by the publishers specifically for the purpose of writing a review. These gifts and referral fees do not affect my opinions; I often give bad reviews anyway.

We use Google third-party advertising companies to serve ads when you visit our website. These companies may use information (not including your name, address, email address, or telephone number) about your visits to this and other websites in order to provide advertisements about goods and services of interest to you. If you would like more information about this practice and to know your choices about not having this information used by these companies, click here.

My Hard Truths about Easy Money on the Internet will show you how to make money on the Internet!

book graphic Internet Income guide



Buy Kerio from a dealer who knows tech: I sell and support

Kerio Connect Mail server, Control, Workspace and Operator licenses and subscription renewals
pavatar.jpg

This post tagged:

       - Blogging
       - Code
       - Perl
       - Programming
       - Security




Unix/Linux Consultants

Skills Tests

Guest Post Here