From 60622ee84352ed857c5f87f935a76e1f9e9fc41e Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Fri, 3 Jan 2014 01:09:21 +0530 Subject: [PATCH] add upload_document action --- bin/pandora_client | 2 +- pandora_client/__init__.py | 38 +++++++++++++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/bin/pandora_client b/bin/pandora_client index 6ad4ddd..5c3aaab 100755 --- a/bin/pandora_client +++ b/bin/pandora_client @@ -37,7 +37,7 @@ if __name__ == '__main__': parser.print_help() sys.exit(1) - actions = ('scan', 'sync', 'upload', 'upload_frames', 'extract', 'clean', 'cmd', 'import_srt') + actions = ('scan', 'sync', 'upload', 'upload_frames', 'extract', 'clean', 'cmd', 'import_srt', 'upload_document') config = ('config', 'add_volume') server = ('server', 'client') if not args or args[0] not in actions + config + server: diff --git a/pandora_client/__init__.py b/pandora_client/__init__.py index 7bbe460..da65b3f 100644 --- a/pandora_client/__init__.py +++ b/pandora_client/__init__.py @@ -723,7 +723,43 @@ class Client(object): r = self.api.uploadFrames(i, {}) if r.get('status', {}).get('code') != 200: print r - + + def upload_document(self, args): + if not self.user: + print "you need to login" + return + conn, c = self._conn() + for f in args: + if f.split('.')[-1] not in ('jpg', 'pdf', 'png'): + print 'unsupported format', f + continue + url = '%supload/document/' % self._config['url'] + r = self.api.upload_chunks(url, f, { + 'filename': os.path.basename(f) + }) + ''' + if r: + oshash = ox.oshash(f) + r = self.api.findDocuments({ + "keys": ['id'], + "query": { + "conditions": [{"key": 'oshash', "value": oshash, "operator": '=='}], + "operator": '&' + } + }) + did = r['data']['items'][0]['id'] + if description: + r = api.editDocument({ + 'id': did, + 'description': descriptoin + }) + if item: + r = api.addDocument({ + 'id': did, + 'item': item + }) + ''' + def files(self, prefix): if not prefix.endswith('/'): prefix += '/'