Skip to content

Advanced Search Filters #11

@Adesoji1

Description

@Adesoji1

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions