From 65fba959b2f98abe1c172dfd93d716bc2b172d9d Mon Sep 17 00:00:00 2001 From: eeckert Date: Thu, 10 Aug 2023 11:41:00 -0600 Subject: [PATCH] rename;threading stalled --- Download-SnapperReports.ps1 | 74 +++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 Download-SnapperReports.ps1 diff --git a/Download-SnapperReports.ps1 b/Download-SnapperReports.ps1 new file mode 100644 index 0000000..118572a --- /dev/null +++ b/Download-SnapperReports.ps1 @@ -0,0 +1,74 @@ +$APIToken = 'iXZU8DNKth2qWaDjDck9' +$APIUrl = 'https://app3.archisnapper.com/api/public/v1/' + +$url_APIToken = '?auth_token=' + $APIToken + +$header = @{ + auth_token = $APIToken +} | ConvertTo-Json + +$OutputPathBase = "M:\N-Data\FieldReports\TestPath" + +# 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 + Write-Host "Processing:" $project_Name -foregroundcolor Green + + + # $project.visits | foreach -Parallel { + # $pathExist = Test-Path $USING:OutputPathBase_Project -ErrorAction SilentlyContinue + # if (!($pathExist)) { + # New-Item -Path $USING:OutputPathBase_Project -ItemType Directory + # } + # if ($_) { + # $testURI = $_.pdf_link + '&auth_token=' + $USING:APIToken + # $Outfile = $USING:OutputPathBase_Project + '\' + $_.unique_id + ".pdf" + # Invoke-WebRequest -Uri $testURI -OutFile $Outfile -TimeoutSec 300 + # } + # } -ThrottleLimit 5 + + foreach ($visit in $Project.visits) { + $pathExist = Test-Path $OutputPathBase_Project -ErrorAction SilentlyContinue + if (!($pathExist)) { + New-Item -Path $OutputPathBase_Project -ItemType Directory + } + if ($visit) { + $testURI = $visit.pdf_link + '&auth_token=' + $APIToken + $Outfile = $OutputPathBase_Project + '\' + $visit.unique_id + ".pdf" + if (!(Test-Path $Outfile)) { + Write-Host "Saving file: " $Outfile + Invoke-WebRequest -Uri $testURI -OutFile $Outfile + + } + + } + } + $page++ + } + + + +} until ( + $response.Content -eq $null +) + + + + + + + + + +