National+Geographic+PoD+downloader+script

code format="python"
 * 1) python script to get daily national geographic photo and make it the desktop picture

the_os = "gnome" #options are "mac" and "gnome" size = "sw"	#options are "xl", "lw" and "sw" ng_dir = "~/Pictures/NG_Daily/"

import urllib2, string, urllib, time, os, time from shutil import copy

try: os.chdir( os.path.expanduser (ng_dir) ) except: os.makedirs( os.path.expanduser (ng_dir) ) os.chdir( os.path.expanduser (ng_dir) )

now = time.localtime(time.time) date = time.strftime("%Y%m%d", now) daily_img_file = "ng_" + date + ".jpg"

f = urllib2.urlopen('http://photography.nationalgeographic.com/photography/photo-of-the-day') page_text = f.read img_link = '', index) start_link = string.find(page_text, 'paper/', index) + 6

file_name = page_text[start_link:end_link] print file_name

f = urllib2.urlopen('http://photography.nationalgeographic.com/photography/wallpaper/' + file_name) page_text = f.read img_link = '', index) start_link = string.find(page_text, '/staticfiles/NGS/Shared/StaticFiles/Photography/Images/POD/', index) + 59

file_name = page_text[start_link:end_link] print file_name

base_file_name = file_name[:-6] extension = file_name[-4:]
 * 1) http://photography.nationalgeographic.com/staticfiles/NGS/Shared/StaticFiles/Photography/Images/POD/h/huli-ceremonial-dance-650271-xl.jpg

if size == "xl": file_name = base_file_name + 'xl' + extension elif size == "lw": file_name = base_file_name + 'lw' + extension

base_url = 'http://photography.nationalgeographic.com/staticfiles/NGS/Shared/StaticFiles/Photography/Images/POD/'

url = base_url + file_name

print url

loc = urllib.urlretrieve(url, daily_img_file) img_file = loc[0]


 * 1) 
 * 2) 'http://lava.nationalgeographic.com/pod/pictures/lg_wallpaper/MM7095_50013.jpg'


 * 1) time.sleep(5)


 * 1) set desktop background on Mac OS X

if the_os == "mac": a1 = """	tell application "Finder" to set desktop picture to alias (POSIX file """

a2 = '"' + os.getcwd + '/' + img_file + '"'

a3 = """ as text)"""

applescript = a1+a2+a3

os.system("osascript -l AppleScript -e '%s'" % applescript)

elif the_os == "gnome": cmd = "gconftool-2 --type=string " pic = os.getcwd + '/' + img_file cmd += "--set /desktop/gnome/background/picture_filename %s " % pic option = "stretched" cmd += "--set /desktop/gnome/background/picture_options %s" % option
 * 1) set desktop background on Linux (using Gnome window manager)

os.system(cmd)

#gconftool-2 --direct --config-source xml:readwrite:/etc/gconf/gconf.xml.defaults --type string --set /desktop/gnome/background/picture_filename filename.png

code