Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Advanced Search Filters #11

Open
Adesoji1 opened this issue Oct 28, 2023 · 0 comments
Open

Advanced Search Filters #11

Adesoji1 opened this issue Oct 28, 2023 · 0 comments

Comments

@Adesoji1
Copy link

Adesoji1 commented Oct 28, 2023

for the love of ruby, can we also implement Geolocation Filtering: Ability to filter photos based on geolocation data, if available. In addition,Date Range Filtering: Ability to search photos within a specific date range.

require 'pexels'
require 'open-uri'

# # Ensure that the API key is set in the environment variable PEXELS_API_KEY
client = Pexels::Client.new(ENV['PEXELS_API_KEY'])


client = Pexels::Client.new

def download_image(url, filename)
  File.open(filename, 'wb') do |file|
    file.write(URI.open(url).read)
  end
end

photos = client.photos.search(
  'United Kingdom', 
  per_page: 2,
  page: 1,
  geolocation: '51.4875, -0.1694', # Latitude and Longitude of Chelsea, London
  date_range: '2023-01-01,2023-10-28'  # Example: Download photos uploaded between Jan 1, 2023, and Oct 28, 2023
)

photos.photos.each_with_index do |photo, index|
  download_image(photo.src['original'], "photo_#{index + 1}.jpg")
  puts "Downloaded photo_#{index + 1}.jpg"
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant