Created
August 23, 2016 10:44
-
-
Save chrisbrownie/47e29c2b2ccdcdbed3f8807a1a539b00 to your computer and use it in GitHub Desktop.
Downloads all DAP charts from AirServices
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
# 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