diff --git a/add_number.py b/add_number.py index 13a9977..63922ee 100755 --- a/add_number.py +++ b/add_number.py @@ -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({ diff --git a/rename_document_series.py b/rename_document_series.py new file mode 100755 index 0000000..d2a29b1 --- /dev/null +++ b/rename_document_series.py @@ -0,0 +1,29 @@ +#!/usr/bin/python3 +import sys +import ox.api + +if len(sys.argv) != 4: + print('usage: %s ' % 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 + }) +