You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Unsplash.configure do |config|
config.application_access_key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
config.application_secret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
config.utm_source = "Recommendation_Travels"
end
Search for photos with the keyword "Dubai"
search_results = Unsplash::Photo.search("Dubai")
Initialize a counter for file naming
counter = 1
Download the photos and trigger the download tracking
search_results.each do |photo|
Format the counter to have leading zeros, creating a filename like dubai_001.jpg
filename = "dubai_#{format('%03d', counter)}.jpg"
Download the photo with an extended timeout (e.g., 30 seconds)
download_url = photo.urls.full
uri = URI(download_url)
http = Net::HTTP.new(uri.host, uri.port)
http.read_timeout = 30 # Set the timeout to 30 seconds
response = http.request_get(uri)
if response.code.to_i == 200
File.open(filename, 'wb') do |file|
file.write response.body
end
else
puts "Failed to download photo: HTTP response code #{response.code}"
end
Trigger the download tracking for attribution
Unsplash::Photo.find(photo.id).track_download
Increment the counter for the next filename
counter += 1
end
puts "Downloaded and tracked #{search_results.size} photos of Dubai."
Observed Behaviour
Image or video please.
Expected Behaviour
ruby download_photo.rb
W, [2023-11-01T21:32:13.826060 #162007] WARN -- : The tags property in this endpoint is deprecated. https://changelog.unsplash.com/deprecations/2021/07/12/tags-search-deprecation.html
Traceback (most recent call last):
16: from download_photo.rb:56:in <main>' 15: from /home/adesoji/gems/gems/delegate-0.3.0/lib/delegate.rb:87:in method_missing'
14: from /home/adesoji/gems/gems/delegate-0.3.0/lib/delegate.rb:87:in each' 13: from download_photo.rb:66:in block in
'
12: from /usr/lib/ruby/2.7.0/net/http.rb:1393:in request_get' 11: from /usr/lib/ruby/2.7.0/net/http.rb:1483:in request'
10: from /usr/lib/ruby/2.7.0/net/http.rb:933:in start' 9: from /usr/lib/ruby/2.7.0/net/http.rb:1485:in block in request'
8: from /usr/lib/ruby/2.7.0/net/http.rb:1492:in request' 7: from /usr/lib/ruby/2.7.0/net/http.rb:1518:in transport_request'
6: from /usr/lib/ruby/2.7.0/net/http.rb:1567:in begin_transport' 5: from /usr/lib/ruby/2.7.0/net/http.rb:958:in connect'
4: from /home/adesoji/gems/gems/timeout-0.4.0/lib/timeout.rb:193:in timeout' 3: from /home/adesoji/gems/gems/timeout-0.4.0/lib/timeout.rb:186:in block in timeout'
2: from /usr/lib/ruby/2.7.0/net/http.rb:960:in block in connect' 1: from /usr/lib/ruby/2.7.0/net/http.rb:960:in open'
/usr/lib/ruby/2.7.0/net/http.rb:960:in `initialize': Failed to open TCP connection to images.unsplash.com:443 (execution expired) (Net::OpenTimeout)
Technical Notes
Rubv version 2.7
Can anyone help me out? i want to download the pictures of Dubai
The text was updated successfully, but these errors were encountered:
Steps to Reproduce
require 'unsplash'
require 'open-uri'
require 'net/http'
Configure the Unsplash gem
Unsplash.configure do |config|
config.application_access_key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
config.application_secret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
config.utm_source = "Recommendation_Travels"
end
Search for photos with the keyword "Dubai"
search_results = Unsplash::Photo.search("Dubai")
Initialize a counter for file naming
counter = 1
Download the photos and trigger the download tracking
search_results.each do |photo|
Format the counter to have leading zeros, creating a filename like dubai_001.jpg
filename = "dubai_#{format('%03d', counter)}.jpg"
Download the photo with an extended timeout (e.g., 30 seconds)
download_url = photo.urls.full
uri = URI(download_url)
http = Net::HTTP.new(uri.host, uri.port)
http.read_timeout = 30 # Set the timeout to 30 seconds
response = http.request_get(uri)
if response.code.to_i == 200
File.open(filename, 'wb') do |file|
file.write response.body
end
else
puts "Failed to download photo: HTTP response code #{response.code}"
end
Trigger the download tracking for attribution
Unsplash::Photo.find(photo.id).track_download
Increment the counter for the next filename
counter += 1
end
puts "Downloaded and tracked #{search_results.size} photos of Dubai."
Observed Behaviour
Expected Behaviour
ruby download_photo.rb
'W, [2023-11-01T21:32:13.826060 #162007] WARN -- : The tags property in this endpoint is deprecated. https://changelog.unsplash.com/deprecations/2021/07/12/tags-search-deprecation.html
Traceback (most recent call last):
16: from download_photo.rb:56:in
<main>' 15: from /home/adesoji/gems/gems/delegate-0.3.0/lib/delegate.rb:87:in
method_missing'14: from /home/adesoji/gems/gems/delegate-0.3.0/lib/delegate.rb:87:in
each' 13: from download_photo.rb:66:in
block in12: from /usr/lib/ruby/2.7.0/net/http.rb:1393:in
request_get' 11: from /usr/lib/ruby/2.7.0/net/http.rb:1483:in
request'10: from /usr/lib/ruby/2.7.0/net/http.rb:933:in
start' 9: from /usr/lib/ruby/2.7.0/net/http.rb:1485:in
block in request'8: from /usr/lib/ruby/2.7.0/net/http.rb:1492:in
request' 7: from /usr/lib/ruby/2.7.0/net/http.rb:1518:in
transport_request'6: from /usr/lib/ruby/2.7.0/net/http.rb:1567:in
begin_transport' 5: from /usr/lib/ruby/2.7.0/net/http.rb:958:in
connect'4: from /home/adesoji/gems/gems/timeout-0.4.0/lib/timeout.rb:193:in
timeout' 3: from /home/adesoji/gems/gems/timeout-0.4.0/lib/timeout.rb:186:in
block in timeout'2: from /usr/lib/ruby/2.7.0/net/http.rb:960:in
block in connect' 1: from /usr/lib/ruby/2.7.0/net/http.rb:960:in
open'/usr/lib/ruby/2.7.0/net/http.rb:960:in `initialize': Failed to open TCP connection to images.unsplash.com:443 (execution expired) (Net::OpenTimeout)
Technical Notes
Can anyone help me out? i want to download the pictures of Dubai
The text was updated successfully, but these errors were encountered: