add prefix

This commit is contained in:
j 2020-03-30 15:14:36 +02:00
parent 7ce7b0cc0e
commit 116f4ef951

31
cleanup/add_title_prefix.py Executable file
View file

@ -0,0 +1,31 @@
#!/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
})