Skip to content

Instantly share code, notes, and snippets.

@viperscape
Created November 6, 2014 00:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save viperscape/201c0e9c934dbce17ecd to your computer and use it in GitHub Desktop.
Save viperscape/201c0e9c934dbce17ecd to your computer and use it in GitHub Desktop.
pull down hi-res of nasa astronomical pic of the day
import urllib.request
address = 'http://apod.nasa.gov/apod/astropix.html'
file = urllib.request.urlopen(address) #read in the site and hunt for the image url
html = file.read()
data = html.decode('utf-8')
#print (data)
s = data.find("<a href=\"image")+14 #find the first instance of the image hyperlink
e = data.find("\"",s) #find the end of this hyperlink
iurl = "http://apod.nasa.gov/image" + data[s:e] #slice out the image url and tack on the full url
print (iurl)
i = data[s:e].split('/')
urllib.request.urlretrieve(iurl,'/home/chris/Backgrounds/NASA/'+i[len(i)-1]) #saves as filename found from site
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment