Created
December 12, 2012 09:28
-
-
Save biesnecker/4266376 to your computer and use it in GitHub Desktop.
Because sometimes you need to get pictures of kittens into your browser from the command line, fast. Usage: rflick.rb "search query" It will open the image in your browser (on OSX)
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
#!/usr/bin/env ruby | |
require 'flickraw' | |
FlickRaw.api_key = "YOUR FLICKR API KEY" | |
FlickRaw.shared_secret = "YOUR FLICKR SHARED SECRET" | |
ARGV[0] ||= "kittens" | |
search_query = ARGV[0] | |
results = flickr.photos.search(:text => search_query) | |
n = results.count - 1 | |
idx = Random.rand(0..n) | |
p = results[idx] | |
farm = p['farm'] | |
server = p['server'] | |
secret = p['secret'] | |
id = p['id'] | |
url = "http://farm#{farm}.staticflickr.com/#{server}/#{id}_#{secret}.jpg" | |
exec("open #{url}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment