From ab5755117907a5e4f55e3b508c75f4f5220c6333 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Thu, 30 May 2019 14:48:16 -0700 Subject: journal_metadata import: allow KBART updates --- python/fatcat_tools/importers/journal_metadata.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'python/fatcat_tools/importers') diff --git a/python/fatcat_tools/importers/journal_metadata.py b/python/fatcat_tools/importers/journal_metadata.py index 89ad6fc0..d24b4103 100644 --- a/python/fatcat_tools/importers/journal_metadata.py +++ b/python/fatcat_tools/importers/journal_metadata.py @@ -110,16 +110,27 @@ class JournalMetadataImporter(EntityImporter): except fatcat_client.rest.ApiException as err: if err.status != 404: raise err - # doesn't exist, need to update + + if not existing: + # doesn't exist, create it return True - # eventually we'll want to support "updates", but for now just skip if - # entity already exists - if existing: + # for now, only update KBART, and only if there is new content + if not existing.extra: + existing.extra = dict() + if ce.extra.get('kbart') and (existing.extra.get('kbart') != ce.extra['kbart']): + if not existing.extra.get('kbart'): + existing.extra['kbart'] = {} + existing.extra['kbart'].update(ce.extra['kbart']) + self.api.update_container(self.get_editgroup_id(), existing.ident, existing) + self.counts['update'] += 1 + return False + else: self.counts['exists'] += 1 return False - return True + # if we got this far, it's a bug + raise NotImplementedError def insert_batch(self, batch): self.api.create_container_auto_batch(fatcat_client.ContainerAutoBatch( -- cgit v1.2.3