From e7cec4cc46339dcb0c79a0d5e5bdf20ca0a68a3a Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Wed, 9 Jul 2014 20:31:20 +0200 Subject: [PATCH] update info is async now --- pandora_client/__init__.py | 47 ++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 27 deletions(-) diff --git a/pandora_client/__init__.py b/pandora_client/__init__.py index 4dc6443..11a0da1 100644 --- a/pandora_client/__init__.py +++ b/pandora_client/__init__.py @@ -610,21 +610,7 @@ class Client(object): r = self.api.update(post) if r['data']['info']: - info = r['data']['info'] - max_info = 100 - total = len(info) - sent = 0 - for offset in range(0, total, max_info): - post = {'info': {}, 'upload': True} - post['info'] = self.get_info_for_ids(info[offset:offset+max_info], prefix) - if len(post['info']): - r = self.api.update(post) - sent += len(post['info']) - if sent: - print 'sent info for %s files' % sent - #send empty list to get updated list of requested info/files/data - post = {'info': {}} - r = self.api.update(post) + r = self.update_info(r['data']['info'], prefix) if not 'data' in r: print r @@ -687,18 +673,8 @@ class Client(object): info = r['data']['info'] if info: - print 'info for %d files requested' % len(info) - max_info = 100 - total = len(info) - sent = 0 - for offset in range(0, total, max_info): - post = {'info': {}, 'upload': True} - post['info'] = self.get_info_for_ids(info[offset:offset+max_info]) - if len(post['info']): - r = self.api.update(post) - sent += len(post['info']) - if sent: - print 'uploading info for %d files' % sent + r = self.update_info(info) + sys.exit() if data: print 'encoding and uploading %s videos' % len(data) @@ -736,6 +712,23 @@ class Client(object): self.api.uploadData(path, oshash) break + def update_info(self, info, prefix=None): + if info: + post = {'info': {}, 'upload': True} + post['info'] = self.get_info_for_ids(info, prefix) + r = self.api.update(post) + if 'taskId' in r['data']: + t = self.api.taskStatus(task_id=r['data']['taskId']) + print 'waiting for server ...' + while t['data']['status'] == 'PENDING': + time.sleep(5) + t = self.api.taskStatus(task_id=r['data']['taskId']) + print 'sent info for %s files' % len(post['info']) + #send empty list to get updated list of requested info/files/data + post = {'info': {}} + r = self.api.update(post) + return r + def upload_frames(self, args): if not self.user: print "you need to login"