Created
September 12, 2016 04:18
-
-
Save NickAtNight500/3b60a43326b3606f160d94b047cfde60 to your computer and use it in GitHub Desktop.
FileDownload.py
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
import console | |
import dialogs | |
import appex | |
import os.path | |
import urllib.request, urllib | |
#Make a downloads directory | |
os.chdir(os.path.expanduser('~')) | |
os.chdir(os.path.join(os.getcwd(),'Documents')) | |
test = os.path.isdir('Downloads') | |
print(test) | |
if test == False: | |
print('Downloads created') | |
os.makedirs('Downloads') | |
else: | |
print('Downloads exists') | |
print('Change dir to Downloads') | |
os.chdir(os.path.join(os.getcwd(),'Downloads')) | |
#Test if running as extenstion | |
test = appex.is_running_extension() | |
if test == True: | |
filein = appex.get_url() | |
else: | |
myrun = dialogs.alert('Manual entry?', '','Enter manual URL',"Dummy") | |
if myrun == 1: | |
filein = input("Enter the URL address of file to get:") | |
else: | |
filein = "https://raw.githubusercontent.com/grrrr/py/741ba0500bc49e8f6268f02d23e461649e8d457b/scripts/buffer.py" | |
fileparse = urllib.parse.urlparse(filein) | |
filepath,filename = os.path.split(fileparse.path) | |
fin = urllib.request.urlopen(filein) | |
fout = open(filename,'w') | |
fout.truncate() | |
bytemyfile = fin.read() | |
myfile = bytemyfile.decode("utf-8") | |
fout.write(myfile) | |
print (myfile) | |
fin.close() | |
fout.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment