Skip to content

Instantly share code, notes, and snippets.

@rymc
Created September 1, 2014 10:54
Show Gist options
  • Save rymc/cd47eada3124a140ee22 to your computer and use it in GitHub Desktop.
Save rymc/cd47eada3124a140ee22 to your computer and use it in GitHub Desktop.
Astronomy Picture of the Day
from re import search
from urllib2 import urlopen
root_url = 'http://apod.nasa.gov/apod/'
html = urlopen(root_url).read()
m = search('a href="(.+jpg)\"', html)
img = urlopen(root_url + m.groups()[0]).read()
with open(m.groups()[0].split('/')[-1], 'wb') as w:
w.write(img)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment