Share Pastebin
Guest
Public paste!

maktfri

By: a guest | Jan 25th, 2010 | Syntax: Python | Size: 0.73 KB | Hits: 78 | Expires: Never
Copy text to clipboard
  1. #!/usr/bin/env python
  2. #pythonscript to grab the astronomy picture of the day
  3. import urllib
  4.  
  5. url = "http://apod.nasa.gov/apod/"
  6.  
  7. opener = urllib.FancyURLopener({})
  8. page = opener.open(url)
  9.  
  10. for line in page.readlines():
  11.         if '<a href="image/' in line:
  12.                 picture = line[9:-3]
  13.                 break
  14.  
  15. pictureurl = url+picture
  16.  
  17. image = urllib.URLopener().retrieve(pictureurl, "AstronomyPictureOfTheDay.jpg")
  18.  
  19.  
  20. #Uncomment this section if you want to save the astronomy picture of day, every day.
  21. #Useful since some of these pictures make great wallpapers
  22. #
  23. #for s in picture.split('/'):
  24. #    if '.jpg' in s:
  25. #        picturename = s
  26. #        break
  27. #image = urllib.URLopener().retrieve(pictureurl, picturename)