From e4bea24a2e38ee7e7a982a2c34ea097d1fac8b9b Mon Sep 17 00:00:00 2001 From: j Date: Wed, 31 May 2017 13:36:08 +0200 Subject: [PATCH] raw import --- import_raw.py | 29 ++++++++++++++++++++++++----- upload_documents.py | 4 +++- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/import_raw.py b/import_raw.py index 160ba0c..ec25c4b 100755 --- a/import_raw.py +++ b/import_raw.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python3 # # apt install convert ufraw-batch # @@ -48,6 +48,21 @@ def get_raw(client): files = [f for f in files if f['extension'].lower() in ('cr2', 'nef')] return files +def raw_exists(client, oshash): + r = client.api.findDocuments({ + 'keys': ['id', 'description'], + 'query': { + 'conditions': [ + {'key': 'description', 'value': '[%s]' % oshash, 'operator': '='} + ], + 'operator': '&' + } + }) + if r['data']['items'] and \ + 'Converted from' in r['data']['items'][0]['description']: + return True + return False + def import_raw(client): files = get_raw(client) print('got', len(files), 'raw files') @@ -55,15 +70,18 @@ def import_raw(client): oshash = f['id'] print(oshash) cache = os.path.join(client.media_cache(), os.path.join(*hash_prefix(oshash))) - cache = unicode(cache) - jpg = glob(u'%s/*.jpg' % cache) + if isinstance(cache, bytes): + cache = cache.decode() + jpg = glob('%s/*.jpg' % cache) if jpg: - jpg = jpg[0] + continue + elif raw_exists(client, oshash): + continue else: jpg = None for path in client.path(oshash): if os.path.exists(path): - jpg = os.path.join(cache, u'%s.jpg' % os.path.basename(path).split('.')[0]) + jpg = os.path.join(cache, '%s.jpg' % os.path.basename(path).split('.')[0]) convert_raw(path, jpg) break if jpg and os.path.exists(jpg): @@ -76,6 +94,7 @@ def import_raw(client): }) print('added', oshash, 'to', f['item']) + if __name__ == '__main__': client = pandora_client.Client(os.path.expanduser('~/.ox/client.json'), False) import_raw(client) diff --git a/upload_documents.py b/upload_documents.py index f027f81..51459f1 100755 --- a/upload_documents.py +++ b/upload_documents.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python3 # # upload documents # @@ -31,6 +31,7 @@ def done(oshash): with open(DONE, 'a') as fd: fd.write(oshash + '\n') + if __name__ == '__main__': uploaded = [] if os.path.exists(DONE): @@ -49,5 +50,6 @@ if __name__ == '__main__': break print('uploading %s documents' % len(_documents)) for path, oshash, item in _documents: + print(path, item) client._add_document(path, item) done(oshash)