Skip to content

Instantly share code, notes, and snippets.

@chrisbrownie
Created August 23, 2016 10:44
Show Gist options
  • Save chrisbrownie/47e29c2b2ccdcdbed3f8807a1a539b00 to your computer and use it in GitHub Desktop.
Save chrisbrownie/47e29c2b2ccdcdbed3f8807a1a539b00 to your computer and use it in GitHub Desktop.
Downloads all DAP charts from AirServices
# Downloads all aero charts from Airservices
$hostUri = "http://www.airservicesaustralia.com/aip/current/dap/AeroProcChartsTOC.htm"
$fileTypesToDownload = @("pdf")
# Download the page of charts
$links = Invoke-WebRequest $hostUri | select -ExpandProperty links
# Get a webclient ready for downloading files
$webClient = New-Object System.Net.WebClient
foreach ($link in $links) {
# Is the link of a file type we want to grab?
if ($fileTypesToDownload -contains $link.href.split(".")[-1]) {
# Build a file title
$localPath = Join-Path $pwd $("Y" + $link.href.substring(0,3) + " " + $link.innerText + "." + $link.href.split(".")[-1])
# Build the URL (ASA always seem to use relative links here)
$linkUri = ((Split-Path $hosturi) + "/" + $link.href).Replace("\","/")
# Download the file
"Downloading $linkUri to $localPath"
try {
$webClient.DownloadFile($linkUri,$localPath)
} catch {
Write-Error "Failed to get $linkuri"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment