from Tkinter import *
import os
import urllib
import threading
import time
def logs(b):
f = open('./downloads/log.txt','aw')
f.write ("Archivo %s" % b + "descargado %s \n" % time.strftime("a Horas: %H:%M:%S en Fecha: %D"))
f.close()
def reporthook(blocks_read, block_size, total_size):
if not blocks_read:
myapp.lab1["text"] = "conexión Establecida"
return
if total_size < 0:
myapp.lab1["text"] = "Bloques Leidos " % blocks_read
else:
amount_read = blocks_read * block_size
myapp.lab1["text"] = "Faltan: %d Kb para terminar la Descarga" %((total_size/1024) - (amount_read/1024))
return
class Hilo(threading.Thread ):
def run ( self ):
try:
i = 0
while i==0:
c = myapp.text3.get(1.0, 2.0)
b = c[c.rfind('/',0,len(c))+1:len(c)]
urllib.urlretrieve("%s" % myapp.text3.get(1.0, 2.0), 'downloads/%s' % b, reporthook=reporthook)
myapp.lab1["text"] = "ARCHIVO %s DESCARGADO" % b
logs(b)
myapp.text3.delete(1.0, 2.0)
if myapp.text3.search("http://", 1.0, 1.7):
myapp.lab1["text"] = "CONTINUANDO DESCARGA"
continue;
else:
myapp.lab1["text"] = "NO HAY URLS PARA DESCARGAR"
break;
except:
myapp.lab1["text"] = "ERROR VERIFIQUE conexión Y DIRECCION URL"
class Application(Frame):
def limpiar(self):
myapp.text3.delete(1.0, END)
def download(self):
if os.path.exists("downloads")==0:
os.makedirs("downloads")
Hilo().start()
def salir(self):
myapp.master.destroy()
exit()
def agregar(self):
myapp.text3.insert(END, myapp.text3.clipboard_get()+"\n")
def createWidgets(self):
self.lab0 = Label(self)
self.lab0["text"] = "INTRODUCE DIRECCION A DESCARGAR"
self.lab0["fg"] = "white"
self.lab0["bg"] = "black"
self.lab0["width"] = 50
self.lab0["height"] = 3
self.lab0.pack({"side": "top"})
self.lab1 = Label(self)
self.lab1["text"] = "CONTADOR DESCARGA PREPARADO"
self.lab1["fg"] = "white"
self.lab1["bg"] = "black"
self.lab1["width"] = 80
self.lab1["height"] = 3
self.lab1.pack({"side": "top"})
self.but1 = Button(self)
self.but1["text"] = "AGREGAR URL DEL PORTAPAPELES"
self.but1["fg"] = "white"
self.but1["bg"] = "blue"
self.but1["width"] = 30
self.but1["height"] = 2
self.but1["border"] = 4
self.but1.grid(row = 10, sticky = E, column = 2, pady = 3)
self.but1["command"] = self.agregar
self.but1.pack({"side": "top"})
self.text3 = Text(self)
self.text3["fg"] = "white"
self.text3["bg"] = "black"
self.text3["width"] = 80
self.text3.pack({"side": "top"})
self.but2 = Button(self)
self.but2["text"] = "SALIR"
self.but2["fg"] = "white"
self.but2["bg"] = "blue"
self.but2["width"] = 10
self.but2["height"] = 3
self.but2["border"] = 4
self.but2.grid(row = 10, sticky = E, column = 2, pady = 3)
self.but2["command"] = self.salir
self.but2.pack({"side": "left"})
self.but3 = Button(self)
self.but3["text"] = "LIMPIAR LISTA URL'S"
self.but3["fg"] = "white"
self.but3["bg"] = "blue"
self.but3["width"] = 30
self.but3["height"] = 3
self.but3["border"] = 4
self.but3.grid(row = 10, sticky = E, column = 2, pady = 3)
self.but3["command"] = self.limpiar
self.but3.pack({"side": "left"})
self.but4 = Button(self)
self.but4["text"] = "INICIAR LAS DESCARGAS"
self.but4["fg"] = "white"
self.but4["bg"] = "blue"
self.but4["width"] = 30
self.but4["height"] = 3
self.but4["border"] = 4
self.but4.grid(row = 10, sticky = E, column = 2, pady = 3)
self.but4["command"] = self.download
self.but4.pack({"side": "right"})
def __init__(self, master=None):
Frame.__init__(self, master)
self.pack()
self.createWidgets()
myapp = Application()
myapp.master.title("DOWNLOADER EN LINUX - GET LINUX")
myapp.master.geometry("+600+600")
myapp.master.tk_setPalette("black")
myapp.master.resizable(0,0)
myapp.mainloop()