Skip to content

Instantly share code, notes, and snippets.

@quapka
Created October 7, 2014 22:31
Show Gist options
  • Save quapka/4bbcf76aee49cf914f2e to your computer and use it in GitHub Desktop.
Save quapka/4bbcf76aee49cf914f2e to your computer and use it in GitHub Desktop.
import urllib, cStringIO
import re
PATH = 'some path'
def download_file(path):
print "Attempting to download file from:"
print "URL: {}".format( path )
_file = cStringIO.StringIO(urllib.urlopen( path ).read())
if _file:
print "... successfully read to buffer"
else:
print "ERROR while trying to read from:"
print "URL: {}".format( path )
return
filename = path[::-1].split('/')[0][::-1]
with open(filename, 'w') as f:
f.write( _file.getvalue() )
print "+++ {}".format( filename )
_file.close()
return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment