Skip to content

Commit

Permalink
Merge branch 'master' into fixes
Browse files Browse the repository at this point in the history
# Conflicts:
#	georeference_airport_diagrams_via_db.pl
#	load_dtpp_metadata.pl
  • Loading branch information
Jan Chaloupecky committed Jan 24, 2018
2 parents 1e1201b + dc58a6f commit b611f9c
Show file tree
Hide file tree
Showing 11 changed files with 289 additions and 122 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ pm_to_blib
/tilers_tools
/mbutil
/parallelGdal2tiles
DDTPP*.zip

2 changes: 1 addition & 1 deletion Steps to update to latest cycle.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Steps to update to latest cycle
$previousCycle = 1506
$latestCycle = 1507

mkdir $latestCycle
mkdir "dtpp-${latestCycle}"

#unzip all of the dtpp archives to one directory
unzip -q -u "DDTPP?_20$latestCycle.zip" -d dtpp-$latestCycle
Expand Down
46 changes: 39 additions & 7 deletions chartCounts.pl → chart_counts.pl
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,51 @@
use Getopt::Std;
use Carp;

# Allow use of locally installed libraries in conjunction with Carton
use FindBin '$Bin';
use lib "$FindBin::Bin/local/lib/perl5";
use lib $FindBin::Bin;

#Some subroutines
use GeoReferencePlatesSubroutines;

#database of metadta for dtpp
my $dbfile = "./dtpp.db";
# Options
use vars qw/ %opt /;

# Define the valid command line options
my $opt_string = '';
my $arg_num = scalar @ARGV;

# We need at least one argument
if ( $arg_num < 1 ) {
usage();
exit(1);
}

# This will fail if we receive an invalid option
unless ( getopts( "$opt_string", \%opt ) ) {
usage();
exit(1);
}

# Which cycle to process
my $cycle = $ARGV[0];
say "Supplied cycle: $cycle";

# database of metadta for dtpp
my $dbfile = "./dtpp-$cycle.sqlite";
my $dtppDbh =
DBI->connect( "dbi:SQLite:dbname=$dbfile", "", "", { RaiseError => 1 } )
or croak $DBI::errstr;

#-----------------------------------------------
#Open the locations database
# Open the locations database
our $dbh;
my $sth;

$dbh = DBI->connect(
"dbi:SQLite:dbname=locationinfo.db",
"", "", { RaiseError => 1 },
) or croak $DBI::errstr;
$dbh =
DBI->connect( "dbi:SQLite:dbname=nasr.sqlite", "", "", { RaiseError => 1 }, )
or croak $DBI::errstr;

our (
$TPP_VOLUME, $FAA_CODE, $CHART_SEQ, $CHART_CODE,
Expand Down Expand Up @@ -652,3 +679,8 @@
#Close the locations database
# $sth->finish();
$dbh->disconnect();

sub usage {
say "Usage: $0 <cycle>";
return;
}
102 changes: 102 additions & 0 deletions download_dtpp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-

"""
Download the full set of archives of DTPP edition, either current or next
"""

import json
from urllib.request import Request, urlopen
import errno
import sys
from pprint import pprint
import subprocess
import argparse

__author__ = '[email protected]'


def get_jsonparsed_data(url):
# Build the request
request = Request(url)
request.add_header('accept', 'application/json')

# Get the json
try:
json_response = urlopen(request).read().decode("utf-8")
except:
print("Error getting DTPP information from {}".format(url))
return None

# Parse it
response_dictionary = (json.loads(json_response))

# Return the dictionary
return response_dictionary


if __name__ == '__main__':

# Parse the command line options
parser = argparse.ArgumentParser(
description='Download a specified edition of DTPP archives from FAA')

parser.add_argument(
'-e',
'--edition',
default='current',
metavar='edition',
help='Which edition of the DTPP to download. Can be \'current\' or \'next\'',
required=False)

parser.add_argument(
'-d',
'--directory',
default='.',
metavar='DIRECTORY',
help='Where to store the downloaded files',
required=False)

parser.add_argument(
'-v',
'--verbose',
help='More output',
action='store_true',
required=False)

args = parser.parse_args()

# Set variables from command line options
edition = args.edition
directory = args.directory

# The URL to get data from
url = "https://soa.smext.faa.gov/apra/dtpp/chart?edition={}".format(
edition)

# Get the JSON data and return a dictionary of values from it
response_dictionary = get_jsonparsed_data(url)

# Print some of the values
if response_dictionary:

if args.verbose:
pprint(response_dictionary)

for edition in response_dictionary['edition']:

# The URL of each part of the DTPP set
url = edition['product']['url']

if args.verbose:
pprint(url)

# Download it using wget
subprocess.call(['wget',
'--timestamping',
'--directory-prefix={}'.format(directory),
url])

else:
print("No response from server")
sys.exit(1)
Binary file added example_dtpp-1601.sqlite
Binary file not shown.
Loading

0 comments on commit b611f9c

Please sign in to comment.