raw import
This commit is contained in:
parent
5e9b385cc8
commit
e4bea24a2e
2 changed files with 27 additions and 6 deletions
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue