From 5f46806e1bf74d939569a42bb9f43caec16bb432 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Sat, 31 Dec 2011 20:10:11 +0530 Subject: [PATCH] remaining --- pandora_client/__init__.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/pandora_client/__init__.py b/pandora_client/__init__.py index 0e4a92c..a94e33d 100644 --- a/pandora_client/__init__.py +++ b/pandora_client/__init__.py @@ -432,13 +432,17 @@ class API(ox.API): f = open(filename) fsize = os.stat(filename).st_size done = 0 + start = time.mktime(time.localtime()) chunk = f.read(CHUNK_SIZE) fname = os.path.basename(filename) if isinstance(fname, unicode): fname = fname.encode('utf-8') while chunk: - print '%0.2f%% %s of %s uploaded \r' % ( - 100 * done/fsize, ox.formatBytes(done), ox.formatBytes(fsize)), + elapsed = time.mktime(time.localtime()) - start + remaining = elapsed / (done/fsize) - elapsed + print '%0.2f%% %s of %s done, %s remaining\r' % ( + 100 * done/fsize, ox.formatBytes(done), ox.formatBytes(fsize), + ox.formatDuration(remaining, verbosity=2)), sys.stdout.flush() form = ox.MultiPartForm() form.add_file('chunk', fname, chunk) @@ -466,11 +470,11 @@ class API(ox.API): if DEBUG: print data time.sleep(5) - if data and data['result'] == 1: + if data and data.get('result') == 1: done += len(chunk) chunk = f.read(CHUNK_SIZE) print ' ' - return data and 'result' in data and data['result'] == 1 + return data and 'result' in data and data.get('result') == 1 else: if DEBUG: if 'status' in data and data['status']['code'] == 401: