add prefix

This commit is contained in:
j 2020-03-30 15:14:36 +02:00
parent 7ce7b0cc0e
commit 116f4ef951
1 changed files with 31 additions and 0 deletions

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
})