I usually get my backgrounds from a couple of photo blogs I subscribe to, but using Flickr for my backgrounds was such a good idea (and a good excuse to play with ruby), that I thought I’d give it a shot.
After some trail and error, and some help online, I was able to come up with this ruby script to do the trick. The script will pull the interesting photos for that day, and will try to find the best fit for your screen resolution. If you don’t like the current background, you can run the script again to change it. With a simple cron entry you can have fresh background at periodic intervals (I have mine set to every 2 hours).
I created the script under Ubuntu GNOME. If you want to give the script a try, you’ll have to edit the script and put in your Flickr api key and shared secret as well as your screen resolution (unless you’re runing on 1440×900). You’ll also need to have rubygems and the rflickr gem installed.
{ 3 trackbacks }
{ 10 comments… read them below or add one }
you rock! can’t believe something got turned around so quickly.
only problem is that i can’t get it to work. i inserted my API_KEY and SHARED_SECRET into the file as marked, and i have both the rflickr and flickr gems installed, but it’s failing to initialize with Flickr. i’m getting the following:
ruby chg-background.rb
/usr/lib/ruby/gems/1.8/gems/flickr-1.0.0/./flickr.rb:67:in `request’: Invalid API Key (Key not found) (RuntimeError)
from /usr/lib/ruby/gems/1.8/gems/flickr-1.0.0/./flickr.rb:90:in `login’
from /usr/lib/ruby/gems/1.8/gems/flickr-1.0.0/./flickr.rb:61:in `initialize’
from chg-background.rb:25
any thoughts?
should have added that the environment is Ubuntu GNOME, and ruby -v returns:
ruby 1.8.4 (2005-12-24) [i486-linux]
It looks like you have another flickr library installed. You’ll need to uninstall that one because the two different libraries conflict with each other:
gem uninstall flickr
gem install rflickr
ok, that solved part of it, but it didn’t seem to provide me with the auth URI:
ruby chg-background.rb
You must visit #{url} to authorize this application. Press enter when you have done so. This is the only time you will have to do this.
ERR: Invalid frob (108)
/usr/lib/ruby/1.8/xmlrpc/client.rb:414:in `call’: Invalid frob (XMLRPC::FaultException)
from /usr/lib/ruby/gems/1.8/gems/rflickr-2006.02.01/lib/flickr/base.rb:153:in `call_unauth_method’
from /usr/lib/ruby/gems/1.8/gems/rflickr-2006.02.01/lib/flickr/auth.rb:52:in `getToken’
from chg-background.rb:32
am i missing something obvious?
No, I didn’t check that part. I’ve uploaded an updated script. Get that, and the first time you run it you should be shown a URL that you click to authorize the app to connect to Flickr.
I also made a change to the script to not store the auth cache file in the temp directory – this way you won’t have to re-auth when the /tmp directory is cleared out.
excellent – that worked initially. only problem was that on second run, i get this:
ruby chg-background2.rb
chg-background2.rb:72: undefined method `remove’ for File:Class (NoMethodError)
Weird – at least you’re getting closer
All you have to do is change the word ‘remove’ to ‘delete’ to get it to work a second time (it’s strange that remove works for me).
I just updated the script again, adding that remove change as well as some other optimizations (if it works it should cycle through more images and find new images a little faster).
Thanks for the great script. Works perfectly.
Oh that’s nice man. I’ll check it out later on tonight.
Did you have any trouble using cron to call the reload desktop command? I seem to remember when I was playing with my python script that I couldn’t get cron to work. I guessed that was because it wasn’t running on the xhost or something but never got it fixed. Any ideas?
Nope, the cron setup worked for me without a hitch.