Created
June 11, 2012 19:53
-
-
Save mnuck/2912270 to your computer and use it in GitHub Desktop.
Grabs the Astronomy Picture 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
#!/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
I'm on osx as well so not sure if this would work:
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 sys
import subprocess
from PIL.Image import Image
base_url = "http://apod.nasa.gov/apod/"
matcher = r'<IMG SRC="([\w\d./-]+).jpg"'
filename = "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)
if "darwin" in sys.platform:
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'])
elif "linux" in sys.platform:
subprocess.call(['gsettings set org.gnome.desktop.background picture-uri %s' % filename])
else:
im = Image.open(filename).convert("RGB")
with open("C:\badwindows.bmp", "wb") as background:
background.write(image)
subprocess.call(['reg add "hkcu\control panel\desktop" /v wallpaper /t REG_SZ /d "" /f'])
subprocess.call(['reg add "hkcu\control panel\desktop" /v wallpaper /t REG_SZ /d "C:\badwindows.bmp" /f'])
subprocess.call(['reg delete "hkcu\Software\Microsoft\Internet Explorer\Desktop\General" /v WallpaperStyle /f'])
subprocess.call(['reg add "hkcu\control panel\desktop" /v WallpaperStyle /t REG_SZ /d 2 /f'])
subprocess.call(['RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters'])