I'm using the code from this thread to limit my download rate.
How do I incorporate partial downloads resuming with the rate limiting code? The examples I've found use urlopen
instead of urlretrieve
, and the RateLimit
class depends on urlretrieve
.
I'd like to have an external function that controls the partial downloading, without having to change the RateLimit
class:
from throttle import TokenBucket, RateLimit
def retrieve_limit_rate(url, filename, rate_limit):
"""Fetch the contents of urls"""
bucket = TokenBucket(10*rate_limit, rate_limit)
print "rate limit = %.1f kB/s" % (rate_limit,)
print 'Downloading %s...' % filename
rate_limiter = RateLimit(bucket, filename)
#
# What do I put here to allow resuming files?
#
return urllib.urlretrieve(url, filename, rate_limiter)