maktfri
By: a guest | Jan 25th, 2010 | Syntax:
Python | Size: 0.73 KB | Hits: 78 | Expires: Never
#!/usr/bin/env python
#pythonscript to grab the astronomy picture of the day
import urllib
url = "http://apod.nasa.gov/apod/"
opener = urllib.FancyURLopener({})
page = opener.open(url)
for line in page.readlines():
if '<a href="image/' in line:
picture = line[9:-3]
break
pictureurl = url+picture
image = urllib.URLopener().retrieve(pictureurl, "AstronomyPictureOfTheDay.jpg")
#Uncomment this section if you want to save the astronomy picture of day, every day.
#Useful since some of these pictures make great wallpapers
#
#for s in picture.split('/'):
# if '.jpg' in s:
# picturename = s
# break
#image = urllib.URLopener().retrieve(pictureurl, picturename)