Skip to content

Commit 483b338

Browse files
Merge pull request #563 from tZimmermann98/develop
Fallback to regex pub year exraction or empty string in case arrow fails to parse the date
2 parents c19c99b + db06043 commit 483b338

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

scholarly/publication_parser.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,12 @@ def fill(self, publication: Publication)->Publication:
312312
'YYYY/M/DD',
313313
'YYYY/M/D',
314314
'YYYY/MM/D']
315-
publication['bib']['pub_year'] = arrow.get(val.text, patterns).year
315+
try:
316+
publication['bib']['pub_year'] = arrow.get(val.text, patterns).year
317+
except ValueError:
318+
# fallback to regex year extraction if arrow fails
319+
match = re.search(r'\d{4}', val.text)
320+
publication['bib']['pub_year'] = match.group() if match else ""
316321
publication['bib']['pub_date'] = val.text
317322
elif key == 'description':
318323
# try to find all the gsh_csp if they exist

0 commit comments

Comments
 (0)