Created
November 18, 2018 02:32
-
-
Save briandfoy/70b5c1ec94393f0e6cfcafe6bdd1006e to your computer and use it in GitHub Desktop.
Get the tracking info for a single USPS shipment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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