def download(leg, sess, number): leg = int(leg) sess = int(sess) number = int(number) url = encode_url(leg, sess, num) filename = make_filename(leg, sess, number) cmd = 'wget "%s" --quiet --output-document %s' % (url, filename) import subprocess subprocess.call(cmd, shell=True)
def dar_exists(leg, sess, num): url = encode_url(leg, sess, num) # Now we check if there's anything at the URL. # We always get return code 200 since there's a HTML error message, # so we check if we're getting a PDF file or a HTML response. from urllib2 import urlopen response = urlopen(url) mimetype = response.info().values()[-1].split(';')[0] if mimetype == 'application/pdf': return True print "Resource exists!" elif mimetype == 'text/html': return False else: print mimetype raise ValueError