* Tony Vance [Fri,  6 Feb 2004 at 16:20 -0700]
> Hi everyone,
> 
> I got a cool python script from my professor that goes to NASA's 
> astronomy picture of the day, downloads it, and then uses ImageMagick to 
> resize it and composite it with a black background.   Very cool.  I've 
> attached it for those who are interested.

Sorry to resurrect an old thread here, but thought some might enjoy this.
I've modified the script so it'll get the high-res pics instead of the
scaled-down one on the page, and I also added the ability to specify a day
for downloading:
Astronomy.py yymmdd
So if any of you have been using this and want to see what some of the past
days have been, now you can see.
#!/usr/bin/python

# Author:     Conan Albrecht ([EMAIL PROTECTED])
# License:    GNU Public License (www.fsf.org)
# Description Retrieves the astronomy picture of the day

import os
import os.path
import urllib

ASTRONOMY_URL = 'http://antwrp.gsfc.nasa.gov/apod/'
ASTRONOMY_PAGE = 'astropix.html'
if len(sys.argv) > 1:
  DATE = sys.argv[1]
        ASTRONOMY_PAGE = 'ap' + DATE + '.html'
PIC_DIR = "~/pictures/"
CACHE_LOCATION = PIC_DIR + 'Astronomy/'
SCALED_FILE = PIC_DIR + 'AstropixScaled.jpg'
BLACK_BACKGROUND = PIC_DIR + 'BlackBackground.jpg'
FINAL_FILE = PIC_DIR + 'AstropixBackground.jpg'
RESOLUTION = "1400x1050"


# get the URL to the current picture
print "Determining today's picture url..."
for line in urllib.urlopen(ASTRONOMY_URL + ASTRONOMY_PAGE).readlines():
  if line.lower().find('img src=') >= 0:
    pos1 = line.find('"') + 1
    pos2 = line.find('"', pos1)
    pic_url = ASTRONOMY_URL + line[pos1:pos2]
    break

# retrieve it and save to the cache directory
print "Retrieving today's picture..."
localfile = CACHE_LOCATION + os.path.split(pic_url)[1]
urllib.urlretrieve(pic_url, localfile)

# use imagemagick to scale it and apply the black background
print 'Scaling to ' + RESOLUTION + '...'
os.system('convert -scale ' + RESOLUTION + ' ' + localfile + ' ' + SCALED_FILE)
print 'Filling in extra space...'
os.system('composite -gravity Center ' + SCALED_FILE + ' ' + BLACK_BACKGROUND + ' ' + 
FINAL_FILE)

Attachment: pgp00000.pgp
Description: PGP signature

____________________
BYU Unix Users Group 
http://uug.byu.edu/ 
___________________________________________________________________
List Info: http://uug.byu.edu/cgi-bin/mailman/listinfo/uug-list

Reply via email to