2019-12-05 13:08:26 +00:00
|
|
|
#!/usr/bin/python3
|
|
|
|
import re
|
2020-06-28 08:23:21 +00:00
|
|
|
import sys
|
2019-12-05 13:08:26 +00:00
|
|
|
|
|
|
|
import ox
|
|
|
|
import ox.api
|
|
|
|
|
|
|
|
site = 'archive.leftove.rs'
|
|
|
|
api = ox.api.signin('https://%s/api/' % site)
|
|
|
|
|
2020-06-28 08:23:21 +00:00
|
|
|
if len(sys.argv) > 1:
|
|
|
|
collection = sys.argv[1]
|
|
|
|
conditions = [
|
|
|
|
{'key': 'collection', 'operator': '==', 'value': collection}
|
|
|
|
]
|
|
|
|
else:
|
|
|
|
conditions = []
|
|
|
|
|
2019-12-05 13:08:26 +00:00
|
|
|
for regex, fragments in (
|
2020-06-28 15:23:51 +00:00
|
|
|
['Vol. (\d+), No. (\d+)', ['Vol.', 'No.']],
|
|
|
|
['Vol (\d+) no (\d+)', [' Vol ', ' no ']],
|
|
|
|
['Vol:(\d+) #(\d+)', ['Vol:', '#']],
|
|
|
|
#['no (\d+) (\d+)-', [' no ']],
|
2019-12-05 13:08:26 +00:00
|
|
|
):
|
2020-06-28 15:23:51 +00:00
|
|
|
query = {
|
|
|
|
'conditions': [
|
|
|
|
{'key': 'title', 'operator': '=', 'value': fragment}
|
|
|
|
for fragment in fragments
|
|
|
|
] + conditions,
|
|
|
|
'operator': '&'
|
|
|
|
}
|
2019-12-05 13:08:26 +00:00
|
|
|
for doc in api.findDocuments({
|
2020-06-28 15:23:51 +00:00
|
|
|
'query': query,
|
|
|
|
'keys': ['id', 'title', 'volume', 'issue'],
|
2019-12-05 13:08:26 +00:00
|
|
|
'range': [0, 10000]
|
|
|
|
})['data']['items']:
|
2020-06-28 15:23:51 +00:00
|
|
|
if not doc.get('volume', ''):
|
2019-12-05 13:08:26 +00:00
|
|
|
m = re.compile(regex).findall(doc['title'])
|
|
|
|
if m:
|
|
|
|
print(m[0], doc['id'], doc['title'])
|
2020-06-28 15:23:51 +00:00
|
|
|
volume = m[0][0]
|
|
|
|
issue = m[0][1]
|
2019-12-05 13:08:26 +00:00
|
|
|
api.editDocument({
|
|
|
|
'id': doc['id'],
|
2020-06-28 15:23:51 +00:00
|
|
|
'volume': volume,
|
|
|
|
'issue': issue,
|
2019-12-05 13:08:26 +00:00
|
|
|
})
|