52 lines
1.4 KiB
Python
52 lines
1.4 KiB
Python
|
#!/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)
|
||
|
|
||
|
rename = json.load(open(sys.argv[1]))
|
||
|
|
||
|
for old, new in rename.items():
|
||
|
for annotation in api.findAnnotations({
|
||
|
'query': {
|
||
|
'conditions': [{
|
||
|
'key': 'value',
|
||
|
'value': old,
|
||
|
'operator': '=='
|
||
|
},
|
||
|
{
|
||
|
'key': 'layer',
|
||
|
'value': 'keywords',
|
||
|
'operator': '=='
|
||
|
}],
|
||
|
'operator': '&'
|
||
|
},
|
||
|
'keys': ['id', 'in', 'out', 'value', 'user', 'created'],
|
||
|
'range': [0, 500000]
|
||
|
})['data']['items']:
|
||
|
print(annotation['id'], annotation['value'], '->', new)
|
||
|
r = api.editAnnotation({'id': annotation['id'], 'value': new})
|
||
|
print(r.get('status'))
|