Created
April 12, 2013 02:51
-
-
Save jfinstrom/5368934 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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