Last active
October 19, 2022 14:14
-
-
Save ma2shita/bacc21ce32a9883ec17756b67360037a to your computer and use it in GitHub Desktop.
This file contains 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
# Using: | |
# .\export_images.ps1 7CxxxxxxxxCF "2022/10/18 7:00:00" [LOOP_COUNT:19] -Verbose | |
# #=> 001.jpg(+2:00) ~ 019.jpg(+38:00) | |
# Copyright (c) 2022 Kohei "Max" MATSUSHITA (ma2shita+git@ma2shita.jp) | |
# Released under the MIT license | |
# https://opensource.org/licenses/mit-license.php | |
[CmdletBinding()] | |
Param( | |
[string]$DEVICE_ID, | |
[string]$START_DATETIME, | |
[int]$LOOP_COUNT = 19 | |
) | |
Write-Verbose $DEVICE_ID | |
1..$LOOP_COUNT | ForEach-Object { | |
$INC_HOUR=$_ * 2 | |
$TS = ((((Get-Date($START_DATETIME)).AddHours($INC_HOUR) - (Get-Date("1970/1/1 0:0:0 GMT"))).totalSeconds) * 1000) | |
Write-Verbose $TS | |
$EXPORT = soracom sora-cam devices images export --device-id $DEVICE_ID --time $TS | ConvertFrom-Json | |
$GET_EXPORTED = '{"status":null}' | ConvertFrom-Json # do{}until()の代替 / 他の実装と合わせるための記述 | |
while ($GET_EXPORTED.status -ne "completed") { | |
Get-Random -Minimum 3 -Maximum 6 | Start-Sleep | |
$GET_EXPORTED = soracom sora-cam devices images get-exported --device-id $DEVICE_ID --export-id $EXPORT.exportId | ConvertFrom-Json | |
} | |
Invoke-WebRequest $GET_EXPORTED.url -OutFile ("{0:D3}.jpg" -f $_) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment