Skip to content

Instantly share code, notes, and snippets.

@briandfoy
Created November 18, 2018 02:32
Show Gist options
  • Save briandfoy/70b5c1ec94393f0e6cfcafe6bdd1006e to your computer and use it in GitHub Desktop.
Save briandfoy/70b5c1ec94393f0e6cfcafe6bdd1006e to your computer and use it in GitHub Desktop.
Get the tracking info for a single USPS shipment
#!/Users/brian/bin/perls/perl-latest
use v5.26;
use utf8;
use strict;
use warnings;
use lib qw(/Users/brian/Dev/business-us-usps-webtools/lib);
use Business::US::USPS::WebTools::TrackConfirm;
use Term::ANSIColor;
my $tracker = Business::US::USPS::WebTools::TrackConfirm->new( {
UserID => $ENV{USPS_WEBTOOLS_USERID},
Password => $ENV{USPS_WEBTOOLS_PASSWORD},
} );
my $tracking_number = $ARGV[0];
die "Use:\n\t$0 tracking_number\n";
my $details = $tracker->track( TrackID => $tracking_number );
if( $tracker->is_error ) {
warn "Oh No! $tracker->{error}{description}\n";
}
else {
no warnings 'uninitialized';
state @keys = qw(EventTime EventDate Event EventCity );
print color(
$details->[0]{Event} =~ m/Delivered/ ? 'blue' : 'green'
);
printf "%-22s %8s %-20s %s %s\n", $tracking_number, $details->[0]->@{@keys};
print color('reset');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment