pandora_leftovers/cleanup/add_title_prefix.py
2020-03-30 15:14:36 +02:00

31 lines
694 B
Python
Executable file

#!/usr/bin/python3
import re
import sys
import ox
import ox.api
site = 'archive.leftove.rs'
api = ox.api.signin('https://%s/api/' % site)
collection = sys.argv[1]
prefix = sys.argv[2]
for doc in api.findDocuments({
'query': {
'conditions': [
{'key': 'collection', 'operator': '=', 'value': collection}
],
'operator': '&'
},
'keys': ['id', 'title'],
'range': [0, 10000]
})['data']['items']:
if not doc['title'].startswith(prefix):
print(doc['id'], doc['title'])
title = prefix + doc['title']
api.editDocument({
'id': doc['id'],
'title': title
})