pandora_scripts/rename_document_series.py

31 lines
719 B
Python
Raw Permalink Normal View History

2018-08-05 18:00:17 +00:00
#!/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])
2019-06-08 09:32:39 +00:00
sys.exit(1)
2018-08-05 18:00:17 +00:00
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
})