34 lines
743 B
Python
34 lines
743 B
Python
|
#!/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]
|
||
|
search = sys.argv[2]
|
||
|
replace = sys.argv[3]
|
||
|
|
||
|
for doc in api.findDocuments({
|
||
|
'query': {
|
||
|
'conditions': [
|
||
|
{'key': 'collection', 'operator': '=', 'value': collection}
|
||
|
],
|
||
|
'operator': '&'
|
||
|
},
|
||
|
'keys': ['id', 'title'],
|
||
|
'range': [0, 10000]
|
||
|
})['data']['items']:
|
||
|
title = doc['title'].replace(search, replace)
|
||
|
if title != doc['title']:
|
||
|
print(doc['id'], doc['title'])
|
||
|
print('\t->', title)
|
||
|
api.editDocument({
|
||
|
'id': doc['id'],
|
||
|
'title': title
|
||
|
})
|