#!/usr/bin/env python

from urllib import urlretrieve
from string import strip

def firstnonblank(lines):
    for eachLine in lines:
        if strip(eachLine) == '':
            continue
        else:
            return eachLine

def firstlast(webpage):
    f = open(webpage)
    lines = f.readlines()
    f.close()
    print firstnonblank(lines),
    lines.reverse()
    print firstnonblank(lines),

def download(url='http://www', \
            process=firstlast):
    try:
        retval = urlretrieve(url)[0]
    except IOError:
        retval = None
    if retval:
        process(retval)

if __name__ == '__main__':
    download()

