pandora_cms/ontology/update_keywords.py
2018-08-06 19:17:34 +01:00

30 lines
752 B
Python
Executable file

#!/usr/bin/python3
import collections
import json
import ox
import ox.api
site = 'pandora.cinemusespace.com'
api = ox.api.signin('https://%s/api/' % site)
keywords = collections.Counter()
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']:
keyword = annotation['value']
if ': ' not in keyword:
keyword = 'other: ' + keyword
keywords[keyword] += 1
with open('keywords.json', 'w') as fd:
json.dump(keywords, fd, indent=4, ensure_ascii=False, sort_keys=True)