NASA Image of the Day as Gnome background

By Jessy

Lately I’ve really been enjoying the NASA Image of the Day, and so I decided to make a script to update my gnome background daily with the new images. here’s a really great one that came in the other day:

329963main_pia11972_full

I thought of making a nice python script using the elegant universal feed parser; something able to handle generic image feeds, but as soon as i realized how differently the different image feeds were implemented, i quickly gave up in favour of a much more terse solution in bash.

the script below just pulls the rss entry down using wget, and then uses grep to mine out the necessary components of the RSS entry. once it has the image url, it saves that to a directory ~/.backgrounds in your home directory, and then uses gnome’s gconftool-2 to set the value of the background image. add this to your /etc/cron.daily/ directory and you should be good to go. (be careful to copy this exactly– there’s several backticks in the script).

#!/bin/bash
 
# grabs the nasa image of the day by RSS feed and updates the gnome
# background. add this to your cron jobs to have this happen daily.  this is,
# obviously, a hack, that is likely to break at the slightest change of NASA's
# RSS implementation. yay standards!
 
rss=`wget -q -O - http://www.nasa.gov/rss/lg_image_of_the_day.rss`
 
img_url=`echo $rss | grep -o '<enclosure [^>]*>' | grep -o 'http://[^\"]*'`
 
img_name=`echo $img_url | grep -o [^/]*\.\w*$`
 
# this command is benign if the directory already exists.
mkdir -p $HOME/.backgrounds
 
# this command will overwrite the image if it already exists
wget -q -O $HOME/.backgrounds/$img_name $img_url
 
/usr/bin/gconftool-2 -t string --set \
/desktop/gnome/background/picture_filename $HOME/.backgrounds/$img_name

From a developer’s standpoint, I think NASA’s RSS feeds are a great step in the right direction. but this is also an example of an area that, by going just a few steps farther, we could expose hundreds of gigabytes of images a day in ways that would allow developers to actually build on this content, and not just view or scrape it. A rest API where you could query based on mission, image size, instrument, image type, planet, year, etc. would be truly amazing!

Tags: , , , ,

One Comment

  1. Ansgar Schmidt commented on January 8, 2010 | Permalink

    Moin
    Thanks a lot for this script. I was searching for some hints to write exactly this script when I found your blog. Thanks a lot for posting this script!
    Ansgar

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

Archives

  • January 2010
  • November 2009
  • July 2009
  • May 2009
  • April 2009
  • March 2009
  • February 2009
  • January 2009
  • December 2008
  • November 2008
  • Site Feeds

    Posts
    Comments

    Marginal Structure Posts RSS feed

    Site Tags