rename example

This commit is contained in:
j 2018-08-05 19:00:17 +01:00
parent 11b4d7d3a2
commit 1940d6b3dc
2 changed files with 37 additions and 3 deletions

View File

@ -1,14 +1,19 @@
#!/usr/bin/python3
import sys
import ox.api
api = ox.api.signin('https://amp.0x2620.org/api/')
site = sys.argv[1]
prefix = 'cnv'
api = ox.api.signin(site)
n = 1
for item in api.find({
'condtions': [{'key': 'title', 'value': 'cnv', '^'}],
'query': {
'conditions': [{'key': 'title', 'value': prefix, 'operator': '^'}]
},
'keys': ['id', 'title'],
'sort': [{'key': 'created', 'order': '+'}],
'sort': [{'key': 'created', 'operator': '+'}],
'range': [0, 10000]
})['data']['items']:
api.edit({

29
rename_document_series.py Executable file
View File

@ -0,0 +1,29 @@
#!/usr/bin/python3
import sys
import ox.api
if len(sys.argv) != 4:
print('usage: %s <site> <old title prefix> <new title prefix>' % sys.argv[0])
site = sys.argv[1]
old_prefix = sys.argv[2]
new_prefix = sys.argv[2]
api = ox.api.signin(site)
for item in api.findDocuments({
'query': {
'conditions': [{'key': 'title', 'value': old_prefix, 'operator': '='}]
},
'keys': ['id', 'title'],
'sort': [{'key': 'title', 'operator': '+'}],
'range': [0, 10000]
})['data']['items']:
n = int(item['title'][3:])
new_title = '%s %s' % (new_prefix, n)
print(item['title'], '->', new_title)
api.editDocument({
'id': item['id'],
'title': new_title
})