add volume from title

This commit is contained in:
j 2019-12-05 13:08:26 +00:00
parent 7cc92c5c75
commit 97364e4ee7

33
cleanup/add_volume.py Executable file
View file

@ -0,0 +1,33 @@
#!/usr/bin/python3
import re
import ox
import ox.api
site = 'archive.leftove.rs'
api = ox.api.signin('https://%s/api/' % site)
for regex, fragments in (
['Vol. \d+, No. \d+', ['Vol.', 'No.']],
['Vol \d+ no \d+', [' Vol ', ' no ']],
['Vol:\d+ #\d+', ['Vol:', '#']],
):
for doc in api.findDocuments({
'query': {
'conditions': [
{'key': 'title', 'operator': '=', 'value': fragment}
for fragment in fragments
],
'operator': '&'
},
'keys': ['id', 'title', 'volume'],
'range': [0, 10000]
})['data']['items']:
if 'Vol' not in doc.get('volume', ''):
m = re.compile(regex).findall(doc['title'])
if m:
print(m[0], doc['id'], doc['title'])
api.editDocument({
'id': doc['id'],
'volume': m[0].strip()
})