Skip to content

Instantly share code, notes, and snippets.

@jfinstrom
Created April 12, 2013 02:51
Show Gist options
  • Save jfinstrom/5368934 to your computer and use it in GitHub Desktop.
Save jfinstrom/5368934 to your computer and use it in GitHub Desktop.
def grabFile(url, dest):
"""grabFile(fileUrl, saveLocation)
By James Finstrom
Grabs file and saves to specified location
"""
#file = get_threeohtwo(url)
request = urllib2.Request(file)
filename = url.split('/')[-1].split('#')[0].split('?')[0]
request.add_header('User-agent', 'Rhino Python Utility Version:' + script_version)
try:
u = urllib2.urlopen(request)
localFile = open(dest+filename, 'w')
localFile.write(u.read())
localFile.close()
return dest+filename
except URLError, e:
print '%s, %s' % (e.reason, e.code)
return False
except IOError:
print "ERROR writing output... do you have permission to write there?"
return False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment