pandora_leftovers/cleanup/search_replace.py

34 lines
743 B
Python
Raw Normal View History

2020-06-28 15:23:51 +00:00
#!/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
})