add volume

This commit is contained in:
j 2020-06-28 17:23:51 +02:00
commit 2de2e27975
3 changed files with 53 additions and 13 deletions

View file

@ -17,26 +17,31 @@ else:
conditions = []
for regex, fragments in (
['Vol. \d+, No. \d+', ['Vol.', 'No.']],
['Vol \d+ no \d+', [' Vol ', ' no ']],
['Vol:\d+ #\d+', ['Vol:', '#']],
['Vol. (\d+), No. (\d+)', ['Vol.', 'No.']],
['Vol (\d+) no (\d+)', [' Vol ', ' no ']],
['Vol:(\d+) #(\d+)', ['Vol:', '#']],
#['no (\d+) (\d+)-', [' no ']],
):
query = {
'conditions': [
{'key': 'title', 'operator': '=', 'value': fragment}
for fragment in fragments
] + conditions,
'operator': '&'
}
for doc in api.findDocuments({
'query': {
'conditions': [
{'key': 'title', 'operator': '=', 'value': fragment}
for fragment in fragments
] + conditions,
'operator': '&'
},
'keys': ['id', 'title', 'volume'],
'query': query,
'keys': ['id', 'title', 'volume', 'issue'],
'range': [0, 10000]
})['data']['items']:
if 'Vol' not in doc.get('volume', ''):
if not doc.get('volume', ''):
m = re.compile(regex).findall(doc['title'])
if m:
print(m[0], doc['id'], doc['title'])
volume = m[0][0]
issue = m[0][1]
api.editDocument({
'id': doc['id'],
'volume': m[0].strip()
'volume': volume,
'issue': issue,
})