Is there an equivalent to the Unix/Linux "wget" functionality in the
wxPython library? I need to download a file knowing it's full URL. I'd
like to be able to display the progress of the download as well. I'm
not sure if there is a wxPython function to do this. Maybe there's one
in Python? Any help would be much appreciated. I can't seem to find
anything that suits my needs after several web and mailing list
searches.
Consider curl/libcurl/python-pycurl.
Karsten
···
On Mon, Apr 23, 2007 at 12:58:10PM -0400, Richard Querin wrote:
Is there an equivalent to the Unix/Linux "wget" functionality in the
wxPython library? I need to download a file knowing it's full URL. I'd
like to be able to display the progress of the download as well. I'm
not sure if there is a wxPython function to do this. Maybe there's one
in Python?
--
GPG key ID E4071346 @ wwwkeys.pgp.net
E167 67FD A291 2BEA 73BD 4537 78B9 A9F9 E407 1346
Richard Querin wrote:
Is there an equivalent to the Unix/Linux "wget" functionality in the
wxPython library? I need to download a file knowing it's full URL. I'd
like to be able to display the progress of the download as well. I'm
not sure if there is a wxPython function to do this. Maybe there's one
in Python? Any help would be much appreciated. I can't seem to find
anything that suits my needs after several web and mailing list
searches.
For this I always use urllib2. I am not sure if there is a better way but this is how I always do it:
import urllib2
open(localPath, 'wb').write(urllib2.urlopen(remotePath).read())
However you want progress so you must read/write in small increments, so something like:
import urllib2
conn = urllib2.urlopen(remotePath)
localFile = open(localPath, 'wb')
chunkSize = 4096 #number of bytes to read at a time
chunk = conn.read(chunkSize)
while chunk:
localFile.write(chunk)
chunk = conn.read(chunkSize)
downloadFile.close()
Now you have all the data in the file. To display progress you would need to grab the file size (I am sure there is some way in urllib2 but I don't know it off-hand) and keep track of the downloaded kilobytes. I think I have seen a better way to do this than using urlopen but I have never had any issues.
Hopefully this is somewhat useful,
Mike Rooney
Check Python's urllib and urllib2 .
- Josiah
···
"Richard Querin" <rfquerin@gmail.com> wrote:
Is there an equivalent to the Unix/Linux "wget" functionality in the
wxPython library? I need to download a file knowing it's full URL. I'd
like to be able to display the progress of the download as well. I'm
not sure if there is a wxPython function to do this. Maybe there's one
in Python? Any help would be much appreciated. I can't seem to find
anything that suits my needs after several web and mailing list
searches.