Skip to content

Instantly share code, notes, and snippets.

@trakhov
Last active September 12, 2016 18:04
Show Gist options
  • Save trakhov/8769839 to your computer and use it in GitHub Desktop.
Save trakhov/8769839 to your computer and use it in GitHub Desktop.
This ruby script downloads a random photo from flickr.com (search by "1680x1050" and "nature" tags).
require 'flickraw'
require 'open-uri'
FlickRaw.api_key="your api key"
FlickRaw.shared_secret="your secret"
args = {
tags: "1680x1050,nature",
tag_mode: "all",
per_page: 500,
# page: 2,
}
while true
pictures = flickr.photos.search(args).to_a
pic = pictures.sample
info = flickr.photos.getInfo(photo_id: pic['id'])
break if info.respond_to? :originalsecret
end
open(FlickRaw.url_o info) do |src|
binary = src.read
open("your path here/flickr.jpg", 'wb') { |f| f.write binary }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment