64 lines
1.6 KiB
Python
Executable file
64 lines
1.6 KiB
Python
Executable file
#!/usr/bin/python3
|
|
|
|
import getpass
|
|
import json
|
|
import sys
|
|
|
|
import ox
|
|
import ox.web.auth
|
|
|
|
site = 'pandora.cinemusespace.com'
|
|
api = ox.API('https://%s/api/' % site)
|
|
update = False
|
|
try:
|
|
credentials = ox.web.auth.get(site)
|
|
except:
|
|
credentials = {}
|
|
print('Please provide your username and password for %s:' % site)
|
|
credentials['username'] = input('Username: ')
|
|
credentials['password'] = getpass.getpass('Password: ')
|
|
update = True
|
|
r = api.signin(**credentials)
|
|
if 'errors' in r.get('data', {}):
|
|
for kv in r['data']['errors'].items():
|
|
print('%s: %s' % kv)
|
|
sys.exit(1)
|
|
if update:
|
|
ox.web.auth.update(site, credentials)
|
|
|
|
|
|
old = []
|
|
for annotation in api.findAnnotations({
|
|
'query': {
|
|
'conditions': [{
|
|
'key': 'value',
|
|
'value': ', ',
|
|
'operator': '='
|
|
}, {
|
|
'key': 'layer',
|
|
'value': 'keywords',
|
|
'operator': '=='
|
|
}],
|
|
'operator': '&'
|
|
},
|
|
'keys': ['id', 'in', 'out', 'value', 'user', 'created'],
|
|
'range': [0, 50000]
|
|
})['data']['items']:
|
|
item = annotation['id'].split('/')[0]
|
|
for v in annotation['value'].split(', '):
|
|
v = v.strip()
|
|
a = {
|
|
'in': annotation['in'],
|
|
'out': annotation['out'],
|
|
'item': item,
|
|
'layer': 'keywords',
|
|
'value': v,
|
|
}
|
|
print(a)
|
|
r = api.addAnnotation(a)
|
|
print(r.get('status'))
|
|
api.removeAnnotation({'id': annotation['id']})
|
|
old.append(annotation)
|
|
|
|
with open('old.json', 'w') as fd:
|
|
json.dump(old, fd, indent=4, ensure_ascii=False)
|