From c001e6fed7d5ac0bb10ea987e95a8720e91a9f80 Mon Sep 17 00:00:00 2001 From: j Date: Mon, 10 Jun 2019 10:32:58 +0100 Subject: [PATCH] better year detection --- cleanup_collection.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cleanup_collection.py b/cleanup_collection.py index 998d450..de4cad3 100755 --- a/cleanup_collection.py +++ b/cleanup_collection.py @@ -33,13 +33,14 @@ for d in api.findDocuments({ if title != document['title']: edit['title'] = title - year = re.compile('\d{4}').findall(document['title']) - if year and not document.get('date'): + year = re.compile(' \d{4} ').findall(document['title']) + if year and year[0] in ('1', '2') and not document.get('date'): document['date'] = edit['date'] = year[0] if document.get('date') and document['date'] in title: title = title.replace(document['date'], '').strip() - edit['title'] = title + if title: + edit['title'] = title if edit: edit['id'] = d['id']