archisnapper-api/Download-SnapperReports.ps1

62 lines
1.7 KiB
PowerShell
Raw Permalink Normal View History

2023-08-10 11:41:00 -06:00
$APIToken = 'iXZU8DNKth2qWaDjDck9'
$APIUrl = 'https://app3.archisnapper.com/api/public/v1/'
$url_APIToken = '?auth_token=' + $APIToken
$header = @{
auth_token = $APIToken
} | ConvertTo-Json
2023-08-10 13:57:50 -06:00
$OutputPathBase = "C:\Users\eeckert\Downloads\ArchiSnapper"
2023-08-10 11:41:00 -06:00
# get list of projects
# https://docs.archisnapper.com/reference/retrieving-your-projects
$page = 1 # init counter
do {
$URI = $APIUrl + 'sites.json' + $url_APIToken + '&page=' + $page
$response = Invoke-WebRequest -Uri $URI -Method Get
$ProjectList = $response.Content | convertfrom-json
foreach ($project in $ProjectList) {
$project_Name = $Project.name
$project_number = $project.unique_id
$OutputPathBase_Project = $OutputPathBase + '\' + $project_number + '-' + $project_Name
2023-08-10 11:54:59 -06:00
Write-Debug -Message ("Processing: $project_Name") -Debug
2023-08-10 11:41:00 -06:00
2023-08-10 13:19:12 -06:00
$project.visits | foreach -Parallel {
$pathExist = Test-Path $USING:OutputPathBase_Project -ErrorAction SilentlyContinue
2023-08-10 11:41:00 -06:00
if (!($pathExist)) {
2023-08-10 13:19:12 -06:00
New-Item -Path $USING:OutputPathBase_Project -ItemType Directory
2023-08-10 11:41:00 -06:00
}
2023-08-10 13:19:12 -06:00
if ($_) {
Write-Debug -Message ("Checking " + $_.unique_id) -Debug
$testURI = $_.pdf_link + '&auth_token=' + $USING:APIToken
2023-08-10 13:57:50 -06:00
$Outfile = $USING:OutputPathBase_Project + '\' + $_.Date.ToString().Substring(0,10) + '_' + $_.unique_id + ".pdf"
2023-08-10 11:41:00 -06:00
if (!(Test-Path $Outfile)) {
2023-08-10 13:19:12 -06:00
Write-Debug ("Saving file: " + $Outfile) -Debug
2023-08-10 11:41:00 -06:00
Invoke-WebRequest -Uri $testURI -OutFile $Outfile
}
}
2023-08-10 13:19:12 -06:00
} -ThrottleLimit 5
2023-08-10 11:41:00 -06:00
}
2023-08-10 13:19:12 -06:00
$page++
}
2023-08-10 11:41:00 -06:00
2023-08-10 13:19:12 -06:00
until (
$null -eq $response.Content
2023-08-10 11:41:00 -06:00
)