Created
June 2, 2019 02:11
-
-
Save DaryMerckensGT/ef313e031bd912da67d40d737a6bf368 to your computer and use it in GitHub Desktop.
Downloading Lorem Picsum Images
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
JSON.parse(Net::HTTP.get_response(URI.parse("https://picsum.photos/v2/list")).body).collect{ |datum| datum["download_url"] }.map { |url| "#{url.gsub(/unsplash/, "images.unsplash")}.jpg?#{rand >= 0.5 ? "grayscale" : ""}&#{rand >= 0.5 ? "blur=#{(rand*3).ceil}" : ""}" }.each { |url| open(url) { |image| File.open(url.split("/").last.split("?").first, "wb") { |f| f.write(image.read) } } } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment