Skip to content

Instantly share code, notes, and snippets.

@SergioDiniz
Created October 9, 2022 23:52
Show Gist options
  • Save SergioDiniz/9297c527939dec232dffb0541f6ea887 to your computer and use it in GitHub Desktop.
Save SergioDiniz/9297c527939dec232dffb0541f6ea887 to your computer and use it in GitHub Desktop.
download sequential photos from epics.io
import org.apache.commons.io.FileUtils
import java.io.File
import java.net.URL
// download sequential photos from epics.io
fun main(args: Array<String>) {
val baseUrl = "https://images.epics.website/d1d3d313d131d3d13d974e905c985/IMG-IMAGE_CODE.jpg?token=d1d13d13d11d3d12121s32edasd23fwefwsdd&size=767&wm=2&wmlabel=Fotografias"
val photoDestinationPath = "${System.getProperty("user.dir")}/photos"
val imageCodeRange = 5777..6038
imageCodeRange.forEach { imageCode ->
runCatching {
val url = URL(baseUrl.replace("IMAGE_CODE", imageCode.toString()))
val file = File("$photoDestinationPath/IMG-${imageCode}.jpg")
FileUtils.copyURLToFile(url, file)
}.onFailure {
println("Error to download imageCode: $imageCode, message: ${it.message}")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment