Created
November 28, 2011 21:58
-
-
Save BonsaiDen/1402274 to your computer and use it in GitHub Desktop.
Download thing
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
#!/usr/bin/env python3 | |
import urllib.request as m | |
from time import * | |
p = print | |
def get(u, t=None, w=80): | |
p('[get] %s...' % u) | |
r, a, o, ls, w = time(), [0 for i in range(20)], 0, -1, w - 23 | |
def _(b, bs, fs): | |
nonlocal o, ls | |
s, i = int((time() - r) * 10) % 20, b * bs | |
a[s] = (0 if ls != s else a[s]) + (i - o) | |
ls, o, n, c = s, i, sum(a), 0 if i == 0 else 100 / fs * i | |
for x, i in [('by', 0), ('KB', 1), ('MB', 1)]: | |
if n < 1024.0: | |
q = c, ("%3." + str(i) + "f%s") % (n, x), '=' * int(w * (c / 100)), w | |
p(('[%s] [{1:>8}/s] [{2:-<{3}}]' % '{0:>4.1f}%' if c < 100 else 'Done.').format(*q), end='\r' if c < 100 else '\n') | |
break | |
n /= 1024.0 | |
return m.urlretrieve(u, t, _) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
why you no normal variable name