pandora_cms/ontology/update_keywords.py

47 lines
1.1 KiB
Python
Raw Normal View History

2018-05-31 14:59:17 +00:00
#!/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)
keywords = set()
for annotation in api.findAnnotations({
'query': {
'conditions': [{
'key': 'layer',
'value': 'keywords',
'operator': '=='
}],
'operator': '&'
},
'keys': ['id', 'in', 'out', 'value', 'user', 'created'],
'range': [0, 500000]
})['data']['items']:
keywords.add(annotation['value'])
with open('keywords.json', 'w') as fd:
json.dump(list(sorted(keywords)), fd, indent=4)