All pastes #634665 Raw Edit

Someone

public text v1 · immutable
#634665 ·published 2007-07-26 16:04 UTC
rendered paste body
#!/usr/bin/perl

# PDF Retrieval Demonstration Script
# Author: Scott Garner <scott@j38.net>
# Last Updated: 2005-10-20

use strict;
use MacPerl 'DoAppleScript';

# Find the POSIX path to the desktop;

my $desktopPath = MacPerl::DoAppleScript qq{
	return posix path of (path to desktop folder) as text
};

$desktopPath =~ s/^"|"$//g;


print "Enter the package ID for the company in question:\n";

my $packageID = <STDIN>;

chomp $packageID;

my $companyURL = "http://134.186.208.228/caleasi/search.asp?TASKNAME=xshowDocs&PackageID=$packageID";

my $packageSource = `curl -s "$companyURL"`

# Search for the individual documents in the
# package page's source and process each one.

my @docURLs = ($packageSource =~ m{(<a.*xShowPDF.*a>)}ig);
my $curDocURL;

foreach $curDocURL (@docURLs) {
	my $docID;
	my $docName;

	# Extract both the document ID and name from the URL.

	($docID, $docName) = ($curDocURL =~ m{^.*DocID=(\d+).*>(.+)<.*$}i);
	
	# Load the container page--the final PDF document
	# doesn't exist in the expected location until
	# this page has been accessed.

	my $containerURL = "http://134.186.208.228/caleasi/search.asp".
		"?TASKNAME=xShowPDF&DocID=$docID";	
	my $containerSource = `curl -s "$containerURL"`;

	# Retrieve the final PDF using the commandline
	# utility 'curl'.
	
	my $pdfURL = "http://134.186.208.228/caleasi/PDFDocs/$docID.PDF";
	my $pdfPath = qq{"$desktopPath$packageID/$docID-$docName.pdf"};
	`curl --silent --create-dirs --output $pdfPath $pdfURL`;
}

# Tell Finder to beep so the user knows the script
# has finished.

MacPerl::DoAppleScript qq{ tell application "Finder" to beep 2};