raw import

This commit is contained in:
j 2017-05-31 13:36:08 +02:00
parent 5e9b385cc8
commit e4bea24a2e
2 changed files with 27 additions and 6 deletions

View file

@ -1,4 +1,4 @@
#!/usr/bin/python #!/usr/bin/python3
# #
# apt install convert ufraw-batch # 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')] files = [f for f in files if f['extension'].lower() in ('cr2', 'nef')]
return files 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): def import_raw(client):
files = get_raw(client) files = get_raw(client)
print('got', len(files), 'raw files') print('got', len(files), 'raw files')
@ -55,15 +70,18 @@ def import_raw(client):
oshash = f['id'] oshash = f['id']
print(oshash) print(oshash)
cache = os.path.join(client.media_cache(), os.path.join(*hash_prefix(oshash))) cache = os.path.join(client.media_cache(), os.path.join(*hash_prefix(oshash)))
cache = unicode(cache) if isinstance(cache, bytes):
jpg = glob(u'%s/*.jpg' % cache) cache = cache.decode()
jpg = glob('%s/*.jpg' % cache)
if jpg: if jpg:
jpg = jpg[0] continue
elif raw_exists(client, oshash):
continue
else: else:
jpg = None jpg = None
for path in client.path(oshash): for path in client.path(oshash):
if os.path.exists(path): 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) convert_raw(path, jpg)
break break
if jpg and os.path.exists(jpg): if jpg and os.path.exists(jpg):
@ -76,6 +94,7 @@ def import_raw(client):
}) })
print('added', oshash, 'to', f['item']) print('added', oshash, 'to', f['item'])
if __name__ == '__main__': if __name__ == '__main__':
client = pandora_client.Client(os.path.expanduser('~/.ox/client.json'), False) client = pandora_client.Client(os.path.expanduser('~/.ox/client.json'), False)
import_raw(client) import_raw(client)

View file

@ -1,4 +1,4 @@
#!/usr/bin/python #!/usr/bin/python3
# #
# upload documents # upload documents
# #
@ -31,6 +31,7 @@ def done(oshash):
with open(DONE, 'a') as fd: with open(DONE, 'a') as fd:
fd.write(oshash + '\n') fd.write(oshash + '\n')
if __name__ == '__main__': if __name__ == '__main__':
uploaded = [] uploaded = []
if os.path.exists(DONE): if os.path.exists(DONE):
@ -49,5 +50,6 @@ if __name__ == '__main__':
break break
print('uploading %s documents' % len(_documents)) print('uploading %s documents' % len(_documents))
for path, oshash, item in _documents: for path, oshash, item in _documents:
print(path, item)
client._add_document(path, item) client._add_document(path, item)
done(oshash) done(oshash)