ttye0 Moderator


Posts: 107
|
Title: Astronomy Picture of the Day |
Posted on: 10-09-08 13:11
Quote
|
I wanted my Gnome wallpaper to be automatically set to the most recent image on the Astronomy Picture of the Day page whenever I called it so I wrote this dirty little Python script. Just have your system call it when you log in or have cron run it once in awhile.
Code:
import urllib2,re,os
data = urllib2.urlopen("http://apod.nasa.gov/apod").read()
pattern = re.compile('href=\"(image/[0-9]*/.*?\.jpg)\">',re.S)
results = re.findall(pattern,data)
for result in results:
print "Fetching: http://apod.nasa.gov/apod/%s" % result
data = urllib2.urlopen("http://apod.nasa.gov/apod/%s" % result).read()
open(result.split("/")[-1],"wb").write(data)
os.system("gconftool-2 --type string --set /desktop/gnome/background/picture_filename \"%s/%s\"" % (os.getcwd(),result.split("/")[-1]))
|
Each line after the beginning of the 'for' loop should be indented, my forums ignored the indentation...I need to fix that.
Last Edited: 10-09-08 13:18
__________________________________________ CPU: AMD Athlon 64 3700+ Socket 939 1 MB Cache
Motherboard: A8N-SLI Premium
RAM: 3 GB DDR DIMM
|