ccmny

Sun from APOD downloader

Jun 5th, 2012
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.61 KB | None | 0 0
  1. import time
  2. from time import  gmtime, strftime
  3. import os
  4.  
  5. imageURL = "http://sdo.gsfc.nasa.gov/assets/mov/depot/APOD/latest_APOD_HMIC_FR.jpg"
  6.  
  7. def retrieveImage(filename):   
  8.     cmd = "wget " + imageURL + " -O " + filename
  9.     os.system(cmd)
  10.  
  11. try:
  12.     timestr = strftime("%H-%M-%S", gmtime())
  13.     filename = "APOD_HMIC_FR_" + timestr + ".jpg"
  14.     retrieveImage(filename);
  15. except:
  16.     print("Error at " + timestr + ", trying one more time")
  17.     time.sleep(15)
  18.     try:
  19.         timestr = strftime("%H-%M-%S", gmtime())
  20.         filename = "APOD_HMIC_FR_" + timestr + ".jpg"
  21.         retrieveImage(filename)
  22.     except:
  23.         print("Error at " + timestr)
Add Comment
Please, Sign In to add comment