-
-
Save miku/3309992 to your computer and use it in GitHub Desktop.
Grabs the Astronomy Picture of the Day
This file contains hidden or 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
| #!/usr/bin/env python | |
| # Grab the Astronomical Picture of the Day from NASA's site. | |
| # Make it the desktop background, if it's a jpg | |
| # | |
| # Matthew Nuckolls | |
| import urllib2 | |
| import re | |
| import subprocess | |
| base_url = "http://apod.nasa.gov/apod/" | |
| matcher = r'<IMG SRC=\"([\w\d./-]+).jpg"' | |
| filename = "/tmp/background.jpg" | |
| #page = urllib2.urlopen(base_url + "ap120609.html") | |
| page = urllib2.urlopen(base_url + "index.html") | |
| page_data = page.read() | |
| page.close() | |
| m = re.search(matcher,page_data) | |
| if not m: | |
| exit() | |
| image_page = urllib2.urlopen(base_url + m.group(1) + ".jpg") | |
| image = image_page.read() | |
| image_page.close() | |
| with open(filename, "wb") as background: | |
| background.write(image) | |
| subprocess.call(['/usr/bin/osascript', | |
| '-e', 'tell application "Finder"', | |
| '-e', 'set pFile to POSIX file "%s" as string' % filename, | |
| '-e', 'set desktop picture to file pFile', | |
| '-e', 'end tell']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment