Skip to content

Instantly share code, notes, and snippets.

@controversial
Created December 7, 2015 21:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save controversial/f2a3a9e225d4c0ffb62f to your computer and use it in GitHub Desktop.
Save controversial/f2a3a9e225d4c0ffb62f to your computer and use it in GitHub Desktop.
Download URL.py
import urllib2, appex, time, zipfile, os
a=time.time()
if appex.is_running_extension():
url = appex.get_url()
print url
e=0
else:
import clipboard, editor
url = clipboard.get()
e=1
response = urllib2.urlopen(url)
file = response.read()
name = url.split('/')[-1]
home = '/private/var/mobile/Containers/Shared/AppGroup/0BE72E31-5474-44B2-9731-3686B8BF7EDC/Documents/'
output = open(home+name, 'w')
output.write(file)
output.close()
print 'Downloaded '+name+' to /Documents/'+name+' in '+str(time.time()-a)+' seconds'
if zipfile.is_zipfile(home+name):
print 'Extracting zip...'
zipfile.ZipFile(home+name).extractall(home)
os.remove(home+name)
if e:
editor.reload_files()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment