pandora_scripts/rename_document_series.py
2019-06-08 10:32:39 +01:00

30 lines
719 B
Python
Executable file

#!/usr/bin/python3
import sys
import ox.api
if len(sys.argv) != 4:
print('usage: %s <site> <old title prefix> <new title prefix>' % sys.argv[0])
sys.exit(1)
site = sys.argv[1]
old_prefix = sys.argv[2]
new_prefix = sys.argv[2]
api = ox.api.signin(site)
for item in api.findDocuments({
'query': {
'conditions': [{'key': 'title', 'value': old_prefix, 'operator': '='}]
},
'keys': ['id', 'title'],
'sort': [{'key': 'title', 'operator': '+'}],
'range': [0, 10000]
})['data']['items']:
n = int(item['title'][3:])
new_title = '%s %s' % (new_prefix, n)
print(item['title'], '->', new_title)
api.editDocument({
'id': item['id'],
'title': new_title
})