Skip to content

Instantly share code, notes, and snippets.

@lewayotte
Created October 20, 2015 03:59
Show Gist options
  • Save lewayotte/9a1060a0c3b68a82aeea to your computer and use it in GitHub Desktop.
Save lewayotte/9a1060a0c3b68a82aeea to your computer and use it in GitHub Desktop.
PERL script used to scrape all the Nat Geo Trail Map images. Use Photoshop or GIMP later to piece the images together for a good digital copy.
#!/usr/bin/perl
# June 13, 2011
# Lew Ayotte
use strict;
use Getopt::Long;
use File::Path;
# GLOBAL VARIABLES #
my $ASSETS_BASE_URL = 'http://www.natgeomaps.com/assets/files/zoomify/';
my $ZOOM_LEVEL = '5';
my $MAP_BASE_LOCATION = "/home/lewayotte/maps/";
my ( $mapnumber, $maptitle, $rows, $columns );
my $err = 0;
my $quite = " -q ";
GetOptions(
'n=s' => \$mapnumber,
't=s' => \$maptitle,
'r=s' => \$rows,
'c=s' => \$columns
);
if ( !defined( $mapnumber ) || !defined( $maptitle )
|| !defined( $rows ) || !defined( $columns ) ) {
help();
}
for ( my $side = 2; $side <= 3; $side++ ) {
mkpath( $MAP_BASE_LOCATION . $maptitle . '/' . $side );
chdir( $MAP_BASE_LOCATION . $maptitle . '/' . $side );
my $group = 0;
for ( my $row = 0; $row <= $rows; $row++ ) {
for ( my $col = 0; $col <= $columns; $col++ ) {
system( 'wget' . $quite . $ASSETS_BASE_URL . 'ti00000' . $mapnumber . '/ti00000' . $mapnumber . '_' . $side . '_img/TileGroup' . $group . '/' . $ZOOM_LEVEL . '-' . $col . '-' . $row . '.jpg' );
if ( 0 != $? ) {
$group = 1;
$col--;
$err++;
} else {
$err = 0;
}
if ( $err > 10 ) {
die( 'Too many errors recieved' );
}
}
}
}
sub help {
print "Usage: natgeomaps.pl -n MAPNUMBER -t MAPTITLE -c COLUMNS -r ROWS\n";
exit;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment