From 5f79200722d707d406ded1b5afe1ea4951aba332 Mon Sep 17 00:00:00 2001 From: Tobias Zimmermann <77075037+tZimmermann98@users.noreply.github.com> Date: Mon, 3 Feb 2025 11:52:05 +0100 Subject: [PATCH] fallback to regex year extraction or empty String when arrow fails --- scholarly/publication_parser.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scholarly/publication_parser.py b/scholarly/publication_parser.py index 50ff1e4..297360a 100644 --- a/scholarly/publication_parser.py +++ b/scholarly/publication_parser.py @@ -316,7 +316,8 @@ def fill(self, publication: Publication)->Publication: publication['bib']['pub_year'] = arrow.get(val.text, patterns).year except ValueError: # fallback to regex year extraction if arrow fails - publication['bib']['pub_year'] = re.search(r'\d{4}', val.text).group() + match = re.search(r'\d{4}', val.text) + publication['bib']['pub_year'] = match.group() if match else "" publication['bib']['pub_date'] = val.text elif key == 'description': # try to find all the gsh_csp if they exist