Created
November 6, 2014 00:53
-
-
Save viperscape/201c0e9c934dbce17ecd to your computer and use it in GitHub Desktop.
pull down hi-res of nasa astronomical pic of the day
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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