aboutsummaryrefslogtreecommitdiffstats
path: root/python/fatcat_tools
diff options
context:
space:
mode:
authorMartin Czygan <martin.czygan@gmail.com>2019-12-20 17:43:08 +0100
committerMartin Czygan <martin.czygan@gmail.com>2019-12-28 23:07:31 +0100
commit52eabd48658a676ac4577d1c8da31df1fe58093e (patch)
treedb6a2e616c28f39165d6827b8419187685699f40 /python/fatcat_tools
parent403b1a2d4591d878145a021a7c1e15e2d60c47d8 (diff)
downloadfatcat-52eabd48658a676ac4577d1c8da31df1fe58093e.tar.gz
fatcat-52eabd48658a676ac4577d1c8da31df1fe58093e.zip
datacite: move common date patterns out of the loop
Additionally, try the unspecific (%Y) pattern last.
Diffstat (limited to 'python/fatcat_tools')
-rw-r--r--python/fatcat_tools/importers/datacite.py7
1 files changed, 4 insertions, 3 deletions
diff --git a/python/fatcat_tools/importers/datacite.py b/python/fatcat_tools/importers/datacite.py
index 9774e334..77ce1012 100644
--- a/python/fatcat_tools/importers/datacite.py
+++ b/python/fatcat_tools/importers/datacite.py
@@ -280,6 +280,10 @@ class DataciteImporter(EntityImporter):
'Created',
'Updated',
)
+
+ # Before using (expensive) dateparser, try a few common patterns.
+ common_patterns = ('%Y-%m-%d', '%Y-%m', '%Y-%m-%dT%H:%M:%SZ', '%Y-%m-%dT%H:%M:%S', '%Y')
+
for prio in date_type_prio:
dates = attributes.get('dates', []) or [] # Never be None.
for item in dates:
@@ -289,9 +293,6 @@ class DataciteImporter(EntityImporter):
# Parse out date, use common patterns first, fallback to dateparser.
result, value, year_only = None, item.get('date', ''), False
- # Before using (expensive) dateparser, try a few common patterns.
- common_patterns = ('%Y-%m-%d', '%Y', '%Y-%m', '%Y-%m-%dT%H:%M:%SZ', '%Y-%m-%dT%H:%M:%S')
-
for pattern in common_patterns:
try:
result = datetime.datetime.strptime(value, pattern)